Class SmartDriver<T extends io.appium.java_client.MobileElement>


  • public class SmartDriver<T extends io.appium.java_client.MobileElement>
    extends Object
    The SmartDriver class is a wrapper around a RemoteWebDriver that uses the results of the dev-tools.ai classifier for improved robustness, finding elements visually and avoiding broken selectors.
    • Field Detail

      • isIOS

        public boolean isIOS
      • isEspresso

        public boolean isEspresso
      • driver

        public io.appium.java_client.AppiumDriver<T extends io.appium.java_client.MobileElement> driver
        The driver used by the user that we're wrapping.
      • multiplier

        public double multiplier
        The screen density multiplier
    • Constructor Detail

      • SmartDriver

        public SmartDriver​(io.appium.java_client.AppiumDriver<T> driver,
                           String apiKey,
                           Map<String,​Object> initializationDict)
                    throws IOException
        Constructor, creates a new SmartDriver.
        Parameters:
        driver - The RemoteWebDriver to wrap
        apiKey - Your API key, acquired from smartdriver.dev-tools.ai.
        initializationDict - The configuration options for the driver.
        Throws:
        IOException - If there was an initialization error.
      • SmartDriver

        public SmartDriver​(io.appium.java_client.AppiumDriver<T> driver,
                           String apiKey)
                    throws IOException
        Constructor, creates a new SmartDriver with the default server url (smartdriver.dev-tools.ai), non-interactive mode, and with training enabled.
        Parameters:
        driver - The RemoteWebDriver to wrap
        apiKey - Your API key, acquired from smartdriver.dev-tools.ai.
        Throws:
        IOException - If there was an initialization error.
    • Method Detail

      • implicitlyWait

        public SmartDriver implicitlyWait​(long waitTime)
        Convenience method, implicitly wait for the specified amount of time.
        Parameters:
        waitTime - The number of seconds to implicitly wait.
        Returns:
        This SmartDriver, for chaining convenience.
      • getContext

        public String getContext()
      • getContextHandles

        public Set<String> getContextHandles()
      • getRemoteAddress

        public URL getRemoteAddress()
      • isBrowser

        public boolean isBrowser()
      • setLocation

        public void setLocation​(Location location)
      • executeAsyncScript

        public Object executeAsyncScript​(String script,
                                         Object... args)
      • getKeyboard

        public Keyboard getKeyboard()
      • getMouse

        public Mouse getMouse()
      • get

        public void get​(String url)
      • findElement

        public T findElement​(By locator,
                             String elementName)
      • findElement

        public io.appium.java_client.MobileElement findElement​(By locator)
      • findElements

        public List<T> findElements​(By locator)
      • getCurrentUrl

        public String getCurrentUrl()
      • getPageSource

        public String getPageSource()
      • getScreenshotAs

        public <X> X getScreenshotAs​(OutputType<X> outputType)
      • getSessionId

        public SessionId getSessionId()
      • getTitle

        public String getTitle()
      • getWindowHandle

        public String getWindowHandle()
      • getWindowHandles

        public Set<String> getWindowHandles()
      • quit

        public void quit()
      • resetInputState

        public void resetInputState()
      • setErrorHandler

        public void setErrorHandler​(ErrorHandler handler)
      • setFileDetector

        public void setFileDetector​(FileDetector detector)
      • setLogLevel

        public void setLogLevel​(Level level)
      • findElementByClassName

        public T findElementByClassName​(String using,
                                        String elementName)
        Attempts to find an element by class name.
        Parameters:
        using - The class name of the element to find
        elementName - The label name of the element to be classified. Optional, set null to auto generate an element name.
        Returns:
        The element that was found. Raises an exception otherwise.
      • findElementByClassName

        public T findElementByClassName​(String using)
        Attempts to find an element by class name.
        Parameters:
        using - The class name of the element to find
        Returns:
        The element that was found. Raises an exception otherwise.
      • findElementsByClassName

        public List<T> findElementsByClassName​(String using)
        Attempts to find all elements with the matching class name.
        Parameters:
        using - The class name of the elements to find.
        Returns:
        A List with any elements that were found, or an empty List if no matches were found.
      • findElementByCssSelector

        public T findElementByCssSelector​(String using,
                                          String elementName)
        Attempts to find an element by css selector.
        Parameters:
        using - The css selector of the element to find
        elementName - The label name of the element to be classified. Optional, set null to auto generate an element name.
        Returns:
        The element that was found. Raises an exception otherwise.
      • findElementByCssSelector

        public T findElementByCssSelector​(String using)
        Attempts to find an element by css selector.
        Parameters:
        using - The css selector of the element to find
        Returns:
        The element that was found. Raises an exception otherwise.
      • findElementsByCssSelector

        public List<T> findElementsByCssSelector​(String using)
        Attempts to find all elements with the matching css selector.
        Parameters:
        using - The css selector of the elements to find.
        Returns:
        A List with any elements that were found, or an empty List if no matches were found.
      • findElementById

        public T findElementById​(String using,
                                 String elementName)
        Attempts to find an element by id.
        Parameters:
        using - The id of the element to find
        elementName - The label name of the element to be classified. Optional, set null to auto generate an element name.
        Returns:
        The element that was found. Raises an exception otherwise.
      • findElementById

        public T findElementById​(String using)
        Attempts to find an element by id.
        Parameters:
        using - The id of the element to find
        Returns:
        The element that was found. Raises an exception otherwise.
      • findElementsById

        public List<T> findElementsById​(String using)
        Attempts to find all elements with the matching id.
        Parameters:
        using - The id of the elements to find.
        Returns:
        A List with any elements that were found, or an empty List if no matches were found.
      • findElementByLinkText

        public T findElementByLinkText​(String using,
                                       String elementName)
        Attempts to find an element by link text.
        Parameters:
        using - The link text of the element to find
        elementName - The label name of the element to be classified. Optional, set null to auto generate an element name.
        Returns:
        The element that was found. Raises an exception otherwise.
      • findElementByLinkText

        public T findElementByLinkText​(String using)
        Attempts to find an element by link text.
        Parameters:
        using - The link text of the element to find
        Returns:
        The element that was found. Raises an exception otherwise.
      • findElementsByLinkText

        public List<T> findElementsByLinkText​(String using)
        Attempts to find all elements with the matching link text.
        Parameters:
        using - The link text of the elements to find.
        Returns:
        A List with any elements that were found, or an empty List if no matches were found.
      • findElementByName

        public T findElementByName​(String using,
                                   String elementName)
        Attempts to find an element by name.
        Parameters:
        using - The name of the element to find
        elementName - The label name of the element to be classified. Optional, set null to auto generate an element name.
        Returns:
        The element that was found. Raises an exception otherwise.
      • findElementByName

        public T findElementByName​(String using)
        Attempts to find an element by name.
        Parameters:
        using - The name of the element to find
        Returns:
        The element that was found. Raises an exception otherwise.
      • findElementsByName

        public List<T> findElementsByName​(String using)
        Attempts to find all elements with the matching name.
        Parameters:
        using - The name of the elements to find.
        Returns:
        A List with any elements that were found, or an empty List if no matches were found.
      • findElementByPartialLinkText

        public T findElementByPartialLinkText​(String using,
                                              String elementName)
        Attempts to find an element by partial link text.
        Parameters:
        using - The partial link text of the element to find
        elementName - The label name of the element to be classified. Optional, set null to auto generate an element name.
        Returns:
        The element that was found. Raises an exception otherwise.
      • findElementByPartialLinkText

        public T findElementByPartialLinkText​(String using)
        Attempts to find an element by partial link text.
        Parameters:
        using - The partial link text of the element to find
        Returns:
        The element that was found. Raises an exception otherwise.
      • findElementsByPartialLinkText

        public List<T> findElementsByPartialLinkText​(String using)
        Attempts to find all elements with the matching partial link text.
        Parameters:
        using - The partial link text of the elements to find.
        Returns:
        A List with any elements that were found, or an empty List if no matches were found.
      • findElementByTagName

        public T findElementByTagName​(String using,
                                      String elementName)
        Attempts to find an element by tag name.
        Parameters:
        using - The tag name of the element to find
        elementName - The label name of the element to be classified. Optional, set null to auto generate an element name.
        Returns:
        The element that was found. Raises an exception otherwise.
      • findElementByTagName

        public T findElementByTagName​(String using)
        Attempts to find an element by tag name.
        Parameters:
        using - The tag name of the element to find
        Returns:
        The element that was found. Raises an exception otherwise.
      • findElementsByTagName

        public List<T> findElementsByTagName​(String using)
        Attempts to find all elements with the matching tag name.
        Parameters:
        using - The tag name of the elements to find.
        Returns:
        A List with any elements that were found, or an empty List if no matches were found.
      • findElementByXPath

        public T findElementByXPath​(String using,
                                    String elementName)
        Attempts to find an element by xpath.
        Parameters:
        using - The xpath of the element to find
        elementName - The label name of the element to be classified. Optional, set null to auto generate an element name.
        Returns:
        The element that was found. Raises an exception otherwise.
      • findElementByXPath

        public T findElementByXPath​(String using)
        Attempts to find an element by xpath.
        Parameters:
        using - The xpath of the element to find
        Returns:
        The element that was found. Raises an exception otherwise.
      • findElementsByXPath

        public List<T> findElementsByXPath​(String using)
        Attempts to find all elements with the matching xpath.
        Parameters:
        using - The xpath of the elements to find.
        Returns:
        A List with any elements that were found, or an empty List if no matches were found.
      • findByElementName

        public T findByElementName​(String elementName)
        Finds an element by elementName. Please use findElementByElementName(String) instead.
        Parameters:
        elementName - The label name of the element to be classified.
        Returns:
        An element associated with elementName. Throws NoSuchElementException otherwise.
      • findElementByElementName

        public T findElementByElementName​(String elementName)
        Finds an element by elementName.
        Parameters:
        elementName - The label name of the element to be classified.
        Returns:
        An element associated with elementName. Throws NoSuchElementException otherwise.
      • findByAI

        public T findByAI​(String elementName)
        Finds an elements by elementName. Uses visual AI to find the element.
        Parameters:
        elementName - The label name of the element to be classified.
        Returns:
        An element associated with elementName. Throws NoSuchElementException otherwise.
      • scrollToElement

        public void scrollToElement​(T element,
                                    Boolean scrollUp)
      • scrollPage

        public void scrollPage​(int amount)
      • close

        public void close()