Package ai.devtools.appium
Class SmartDriver<T extends io.appium.java_client.MobileElement>
- java.lang.Object
-
- ai.devtools.appium.SmartDriver<T>
-
public class SmartDriver<T extends io.appium.java_client.MobileElement> extends Object
TheSmartDriverclass is a wrapper around aRemoteWebDriverthat uses the results of the dev-tools.ai classifier for improved robustness, finding elements visually and avoiding broken selectors.
-
-
Field Summary
Fields Modifier and Type Field Description io.appium.java_client.AppiumDriver<T>driverThe driver used by the user that we're wrapping.booleanisEspressobooleanisIOSdoublemultiplierThe screen density multiplier
-
Constructor Summary
Constructors Constructor Description SmartDriver(io.appium.java_client.AppiumDriver<T> driver, String apiKey)Constructor, creates a new SmartDriver with the default server url (smartdriver.dev-tools.ai), non-interactive mode, and with training enabled.SmartDriver(io.appium.java_client.AppiumDriver<T> driver, String apiKey, Map<String,Object> initializationDict)Constructor, creates a new SmartDriver.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Responseexecute(String command)Responseexecute(String command, Map<String,?> parameters)ObjectexecuteAsyncScript(String script, Object... args)ObjectexecuteScript(String script, Object... args)TfindByAI(String elementName)Finds an elements byelementName.TfindByElementName(String elementName)Finds an element byelementName.io.appium.java_client.MobileElementfindElement(By locator)TfindElement(By locator, String elementName)TfindElementByClassName(String using)Attempts to find an element by class name.TfindElementByClassName(String using, String elementName)Attempts to find an element by class name.TfindElementByCssSelector(String using)Attempts to find an element by css selector.TfindElementByCssSelector(String using, String elementName)Attempts to find an element by css selector.TfindElementByElementName(String elementName)Finds an element byelementName.TfindElementById(String using)Attempts to find an element by id.TfindElementById(String using, String elementName)Attempts to find an element by id.TfindElementByLinkText(String using)Attempts to find an element by link text.TfindElementByLinkText(String using, String elementName)Attempts to find an element by link text.TfindElementByName(String using)Attempts to find an element by name.TfindElementByName(String using, String elementName)Attempts to find an element by name.TfindElementByPartialLinkText(String using)Attempts to find an element by partial link text.TfindElementByPartialLinkText(String using, String elementName)Attempts to find an element by partial link text.TfindElementByTagName(String using)Attempts to find an element by tag name.TfindElementByTagName(String using, String elementName)Attempts to find an element by tag name.TfindElementByXPath(String using)Attempts to find an element by xpath.TfindElementByXPath(String using, String elementName)Attempts to find an element by xpath.List<T>findElements(By locator)List<T>findElementsByClassName(String using)Attempts to find all elements with the matching class name.List<T>findElementsByCssSelector(String using)Attempts to find all elements with the matching css selector.List<T>findElementsById(String using)Attempts to find all elements with the matching id.List<T>findElementsByLinkText(String using)Attempts to find all elements with the matching link text.List<T>findElementsByName(String using)Attempts to find all elements with the matching name.List<T>findElementsByPartialLinkText(String using)Attempts to find all elements with the matching partial link text.List<T>findElementsByTagName(String using)Attempts to find all elements with the matching tag name.List<T>findElementsByXPath(String using)Attempts to find all elements with the matching xpath.voidget(String url)CapabilitiesgetCapabilities()CommandExecutorgetCommandExecutor()StringgetContext()Set<String>getContextHandles()StringgetCurrentUrl()ErrorHandlergetErrorHandler()ExecuteMethodgetExecuteMethod()FileDetectorgetFileDetector()KeyboardgetKeyboard()MousegetMouse()ScreenOrientationgetOrientation()StringgetPageSource()URLgetRemoteAddress()<X> XgetScreenshotAs(OutputType<X> outputType)SessionIdgetSessionId()StringgetTitle()StringgetWindowHandle()Set<String>getWindowHandles()SmartDriverimplicitlyWait(long waitTime)Convenience method, implicitly wait for the specified amount of time.booleanisBrowser()Locationlocation()WebDriver.Optionsmanage()WebDriver.Navigationnavigate()voidperform(Collection<Sequence> actions)voidquit()voidresetInputState()voidrotate(DeviceRotation rotation)voidrotate(ScreenOrientation orientation)DeviceRotationrotation()voidscrollPage(int amount)voidscrollToElement(T element, Boolean scrollUp)voidsetErrorHandler(ErrorHandler handler)voidsetFileDetector(FileDetector detector)voidsetLocation(Location location)voidsetLogLevel(Level level)WebDriver.TargetLocatorswitchTo()StringtoString()
-
-
-
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- TheRemoteWebDriverto wrapapiKey- 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- TheRemoteWebDriverto wrapapiKey- 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()
-
getExecuteMethod
public ExecuteMethod getExecuteMethod()
-
getOrientation
public ScreenOrientation getOrientation()
-
getRemoteAddress
public URL getRemoteAddress()
-
isBrowser
public boolean isBrowser()
-
location
public Location location()
-
rotate
public void rotate(DeviceRotation rotation)
-
rotate
public void rotate(ScreenOrientation orientation)
-
rotation
public DeviceRotation rotation()
-
setLocation
public void setLocation(Location location)
-
getKeyboard
public Keyboard getKeyboard()
-
getMouse
public Mouse getMouse()
-
manage
public WebDriver.Options manage()
-
navigate
public WebDriver.Navigation navigate()
-
switchTo
public WebDriver.TargetLocator switchTo()
-
get
public void get(String url)
-
findElement
public io.appium.java_client.MobileElement findElement(By locator)
-
getCapabilities
public Capabilities getCapabilities()
-
getCommandExecutor
public CommandExecutor getCommandExecutor()
-
getCurrentUrl
public String getCurrentUrl()
-
getErrorHandler
public ErrorHandler getErrorHandler()
-
getFileDetector
public FileDetector getFileDetector()
-
getPageSource
public String getPageSource()
-
getScreenshotAs
public <X> X getScreenshotAs(OutputType<X> outputType)
-
getSessionId
public SessionId getSessionId()
-
getTitle
public String getTitle()
-
getWindowHandle
public String getWindowHandle()
-
perform
public void perform(Collection<Sequence> actions)
-
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 findelementName- The label name of the element to be classified. Optional, setnullto 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
Listwith any elements that were found, or an emptyListif 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 findelementName- The label name of the element to be classified. Optional, setnullto 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
Listwith any elements that were found, or an emptyListif 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 findelementName- The label name of the element to be classified. Optional, setnullto 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
Listwith any elements that were found, or an emptyListif 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 findelementName- The label name of the element to be classified. Optional, setnullto 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
Listwith any elements that were found, or an emptyListif 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 findelementName- The label name of the element to be classified. Optional, setnullto 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
Listwith any elements that were found, or an emptyListif 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 findelementName- The label name of the element to be classified. Optional, setnullto 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
Listwith any elements that were found, or an emptyListif 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 findelementName- The label name of the element to be classified. Optional, setnullto 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
Listwith any elements that were found, or an emptyListif 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 findelementName- The label name of the element to be classified. Optional, setnullto 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
Listwith any elements that were found, or an emptyListif no matches were found.
-
findByElementName
public T findByElementName(String elementName)
Finds an element byelementName. Please usefindElementByElementName(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 byelementName.- 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 byelementName. 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.
-
scrollPage
public void scrollPage(int amount)
-
close
public void close()
-
-