Class CapabilityHelpers


  • public class CapabilityHelpers
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String APPIUM_PREFIX  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T getCapability​(org.openqa.selenium.Capabilities caps, java.lang.String name, java.lang.Class<T> expectedType)
      Helper that is used for capability values retrieval.
      static java.lang.Double toDouble​(java.lang.Object value)
      Converts generic capability value to double.
      static java.time.Duration toDuration​(java.lang.Object value)
      Converts generic capability value to duration.
      static java.time.Duration toDuration​(java.lang.Object value, java.util.function.Function<java.lang.Long,​java.time.Duration> converter)
      Converts generic capability value to duration.
      static java.lang.Integer toInteger​(java.lang.Object value)
      Converts generic capability value to integer.
      static java.lang.Long toLong​(java.lang.Object value)
      Converts generic capability value to long.
      static java.lang.Boolean toSafeBoolean​(java.lang.Object value)
      Converts generic capability value to boolean without throwing exceptions.
      static java.net.URL toUrl​(java.lang.Object value)
      Converts generic capability value to a url.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CapabilityHelpers

        public CapabilityHelpers()
    • Method Detail

      • getCapability

        @Nullable
        public static <T> T getCapability​(org.openqa.selenium.Capabilities caps,
                                          java.lang.String name,
                                          java.lang.Class<T> expectedType)
        Helper that is used for capability values retrieval. Supports both prefixed W3C and "classic" capability names.
        Type Parameters:
        T - The corresponding capability type.
        Parameters:
        caps - driver caps object
        name - capability name
        expectedType - the expected capability type
        Returns:
        The retrieved capability value or null if the cap either not present has an unexpected type
      • toSafeBoolean

        @Nullable
        public static java.lang.Boolean toSafeBoolean​(java.lang.Object value)
        Converts generic capability value to boolean without throwing exceptions.
        Parameters:
        value - The capability value.
        Returns:
        null is the passed value is null otherwise the converted value.
      • toInteger

        @Nullable
        public static java.lang.Integer toInteger​(java.lang.Object value)
        Converts generic capability value to integer.
        Parameters:
        value - The capability value.
        Returns:
        null is the passed value is null otherwise the converted value.
        Throws:
        java.lang.NumberFormatException - If the given value cannot be parsed to a valid integer.
      • toLong

        @Nullable
        public static java.lang.Long toLong​(java.lang.Object value)
        Converts generic capability value to long.
        Parameters:
        value - The capability value.
        Returns:
        null is the passed value is null otherwise the converted value.
        Throws:
        java.lang.NumberFormatException - If the given value cannot be parsed to a valid long.
      • toDouble

        @Nullable
        public static java.lang.Double toDouble​(java.lang.Object value)
        Converts generic capability value to double.
        Parameters:
        value - The capability value.
        Returns:
        null is the passed value is null otherwise the converted value.
        Throws:
        java.lang.NumberFormatException - If the given value cannot be parsed to a valid long.
      • toDuration

        @Nullable
        public static java.time.Duration toDuration​(java.lang.Object value)
        Converts generic capability value to duration. The value is assumed to be measured in milliseconds.
        Parameters:
        value - The capability value.
        Returns:
        null is the passed value is null otherwise the converted value.
        Throws:
        java.lang.NumberFormatException - If the given value cannot be parsed to a valid number.
      • toDuration

        @Nullable
        public static java.time.Duration toDuration​(java.lang.Object value,
                                                    java.util.function.Function<java.lang.Long,​java.time.Duration> converter)
        Converts generic capability value to duration.
        Parameters:
        value - The capability value.
        converter - Converts the numeric value to a Duration instance.
        Returns:
        null is the passed value is null otherwise the converted value.
        Throws:
        java.lang.NumberFormatException - If the given value cannot be parsed to a valid number.
      • toUrl

        @Nullable
        public static java.net.URL toUrl​(java.lang.Object value)
        Converts generic capability value to a url.
        Parameters:
        value - The capability value.
        Returns:
        null is the passed value is null otherwise the converted value.
        Throws:
        java.lang.IllegalArgumentException - If the given value cannot be parsed to a valid url.