io.appium.java_client
Class AppiumDriver

java.lang.Object
  extended by org.openqa.selenium.remote.RemoteWebDriver
      extended by io.appium.java_client.AppiumDriver
All Implemented Interfaces:
FindsByAccessibilityId, FindsByAndroidUIAutomator, FindsByIosUIAutomation, MobileDriver, org.openqa.selenium.ContextAware, org.openqa.selenium.HasCapabilities, org.openqa.selenium.interactions.HasInputDevices, org.openqa.selenium.internal.FindsByClassName, org.openqa.selenium.internal.FindsByCssSelector, org.openqa.selenium.internal.FindsById, org.openqa.selenium.internal.FindsByLinkText, org.openqa.selenium.internal.FindsByName, org.openqa.selenium.internal.FindsByTagName, org.openqa.selenium.internal.FindsByXPath, org.openqa.selenium.JavascriptExecutor, org.openqa.selenium.Rotatable, org.openqa.selenium.SearchContext, org.openqa.selenium.TakesScreenshot, org.openqa.selenium.WebDriver

public class AppiumDriver
extends org.openqa.selenium.remote.RemoteWebDriver
implements MobileDriver, org.openqa.selenium.ContextAware, org.openqa.selenium.Rotatable, FindsByIosUIAutomation, FindsByAndroidUIAutomator, FindsByAccessibilityId


Nested Class Summary
 
Nested classes/interfaces inherited from class org.openqa.selenium.remote.RemoteWebDriver
org.openqa.selenium.remote.RemoteWebDriver.RemoteTargetLocator, org.openqa.selenium.remote.RemoteWebDriver.RemoteWebDriverOptions, org.openqa.selenium.remote.RemoteWebDriver.When
 
Nested classes/interfaces inherited from interface org.openqa.selenium.WebDriver
org.openqa.selenium.WebDriver.ImeHandler, org.openqa.selenium.WebDriver.Navigation, org.openqa.selenium.WebDriver.Options, org.openqa.selenium.WebDriver.TargetLocator, org.openqa.selenium.WebDriver.Timeouts, org.openqa.selenium.WebDriver.Window
 
Constructor Summary
AppiumDriver(URL remoteAddress, org.openqa.selenium.Capabilities desiredCapabilities)
           
 
Method Summary
 void closeApp()
          Close the app which was provided in the capabilities at session creation
 MobileElement complexFind(String complex)
           
 org.openqa.selenium.WebDriver context(String name)
           
 String currentActivity()
          Get the current activity being run on the mobile device
 void endTestCoverage(String intent, String path)
          Get test-coverage data Android-only method
protected  org.openqa.selenium.remote.Response execute(String command)
           
 org.openqa.selenium.remote.Response execute(String driverCommand, Map<String,?> parameters)
           
 org.openqa.selenium.WebElement findElementByAccessibilityId(String using)
           
 org.openqa.selenium.WebElement findElementByAndroidUIAutomator(String using)
           
 org.openqa.selenium.WebElement findElementByIosUIAutomation(String using)
           
 List<org.openqa.selenium.WebElement> findElementsByAccessibilityId(String using)
           
 List<org.openqa.selenium.WebElement> findElementsByAndroidUIAutomator(String using)
           
 List<org.openqa.selenium.WebElement> findElementsByIosUIAutomation(String using)
           
 String getAppStrings()
          Get all defined Strings from an Android app for the default language
 String getAppStrings(String language)
          Get all defined Strings from an Android app for the specified language
 String getContext()
           
 Set<String> getContextHandles()
           
 org.openqa.selenium.WebElement getNamedTextField(String name)
          In iOS apps, named TextFields have the same accessibility Id as their containing TableElement.
 org.openqa.selenium.ScreenOrientation getOrientation()
           
 URL getRemoteAddress()
           
 void hideKeyboard()
          Hides the keyboard if it is showing.
 void hideKeyboard(String keyName)
          Hides the keyboard by pressing the button specified by keyName if it is showing.
 void installApp(String appPath)
          Install an app on the mobile device
 boolean isAppInstalled(String bundleId)
          Checks if an app is installed on the device
 void launchApp()
          Launch the app which was provided in the capabilities at session creation
 void lockScreen(int seconds)
          Lock the device (bring it to the lock screen) for a given number of seconds
 void openNotifications()
          Open the notification shade, on Android devices.
 void performMultiTouchAction(MultiTouchAction multiAction)
          Performs multiple TouchAction gestures at the same time, to simulate multiple fingers/touch inputs.
 TouchAction performTouchAction(TouchAction touchAction)
          Performs a chain of touch actions, which together can be considered an entire gesture.
 void pinch(int x, int y)
          Convenience method for pinching an element on the screen.
 void pinch(org.openqa.selenium.WebElement el)
          Convenience method for pinching an element on the screen.
 byte[] pullFile(String remotePath)
           
 byte[] pullFolder(String remotePath)
          Pull a folder from the simulator/device.
 void pushFile(String remotePath, byte[] base64Data)
          Save base64 encoded data as a file on the remote mobile device.
 void removeApp(String bundleId)
          Remove the specified app from the device (uninstall)
 void resetApp()
          Reset the currently running app for this session
 void rotate(org.openqa.selenium.ScreenOrientation orientation)
           
 void runAppInBackground(int seconds)
          Runs the current app as a background app for the number of seconds requested.
 MobileElement scrollTo(String text)
           
 MobileElement scrollToExact(String text)
           
 void sendKeyEvent(int key)
          Send a key event to the device
 void sendKeyEvent(int key, Integer metastate)
          Send a key event along with an Android metastate to an Android device Metastates are things like *shift* to get uppercase characters
 void shake()
          Simulate shaking the device This is an iOS-only method
 void swipe(int startx, int starty, int endx, int endy, int duration)
          Convenience method for swiping across the screen
 void tap(int fingers, int x, int y, int duration)
          Convenience method for tapping a position on the screen
 void tap(int fingers, org.openqa.selenium.WebElement element, int duration)
          Convenience method for tapping the center of an element on the screen
 void zoom(int x, int y)
          Convenience method for "zooming in" on an element on the screen.
 void zoom(org.openqa.selenium.WebElement el)
          Convenience method for "zooming in" on an element on the screen.
 
Methods inherited from class org.openqa.selenium.remote.RemoteWebDriver
close, executeAsyncScript, executeScript, findElement, findElement, findElementByClassName, findElementByCssSelector, findElementById, findElementByLinkText, findElementByName, findElementByPartialLinkText, findElementByTagName, findElementByXPath, findElements, findElements, findElementsByClassName, findElementsByCssSelector, findElementsById, findElementsByLinkText, findElementsByName, findElementsByPartialLinkText, findElementsByTagName, findElementsByXPath, get, getCapabilities, getCommandExecutor, getCurrentUrl, getElementConverter, getErrorHandler, getExecuteMethod, getFileDetector, getKeyboard, getMouse, getPageSource, getRemoteStatus, getScreenshotAs, getSessionId, getTitle, getWindowHandle, getWindowHandles, log, manage, navigate, quit, setCommandExecutor, setElementConverter, setErrorHandler, setFileDetector, setFoundBy, setLogLevel, setSessionId, startClient, startSession, startSession, stopClient, switchTo, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.openqa.selenium.WebDriver
close, findElement, findElements, get, getCurrentUrl, getPageSource, getTitle, getWindowHandle, getWindowHandles, manage, navigate, quit, switchTo
 

Constructor Detail

AppiumDriver

public AppiumDriver(URL remoteAddress,
                    org.openqa.selenium.Capabilities desiredCapabilities)
Method Detail

execute

public org.openqa.selenium.remote.Response execute(String driverCommand,
                                                   Map<String,?> parameters)
Specified by:
execute in interface MobileDriver
Overrides:
execute in class org.openqa.selenium.remote.RemoteWebDriver

execute

protected org.openqa.selenium.remote.Response execute(String command)
Overrides:
execute in class org.openqa.selenium.remote.RemoteWebDriver

resetApp

public void resetApp()
Reset the currently running app for this session


getAppStrings

public String getAppStrings()
Get all defined Strings from an Android app for the default language

Returns:
a string of all the localized strings defined in the app

getAppStrings

public String getAppStrings(String language)
Get all defined Strings from an Android app for the specified language

Parameters:
language - strings language code
Returns:
a string of all the localized strings defined in the app

sendKeyEvent

public void sendKeyEvent(int key)
Send a key event to the device

Parameters:
key - code for the key pressed on the device

sendKeyEvent

public void sendKeyEvent(int key,
                         Integer metastate)
Send a key event along with an Android metastate to an Android device Metastates are things like *shift* to get uppercase characters

Parameters:
key - code for the key pressed on the Android device
metastate - metastate for the keypress

currentActivity

public String currentActivity()
Get the current activity being run on the mobile device


pullFile

public byte[] pullFile(String remotePath)
Parameters:
remotePath - On Android and iOS, this is either the path to the file (relative to the root of the app's file system). On iOS only, if path starts with /AppName.app, which will be replaced with the application's .app directory
Returns:
A byte array of Base64 encoded data.

pushFile

public void pushFile(String remotePath,
                     byte[] base64Data)
Save base64 encoded data as a file on the remote mobile device. This is an Android only method.

Parameters:
remotePath - Path to file to write data to on remote device
base64Data - Base64 encoded byte array of data to write to remote device

pullFolder

public byte[] pullFolder(String remotePath)
Pull a folder from the simulator/device. Does not work on iOS Real Devices, but works on simulators

Parameters:
remotePath - On Android and iOS, this is either the path to the file (relative to the root of the app's file system). On iOS only, if path starts with /AppName.app, which will be replaced with the application's .app directory
Returns:
A byte array of Base64 encoded data, representing a ZIP ARCHIVE of the contents of the requested folder.

hideKeyboard

public void hideKeyboard()
Hides the keyboard if it is showing. This is an iOS only command.


hideKeyboard

public void hideKeyboard(String keyName)
Hides the keyboard by pressing the button specified by keyName if it is showing. This is an iOS only command.

Parameters:
keyName - The button pressed by the mobile driver to attempt hiding the keyboard

runAppInBackground

public void runAppInBackground(int seconds)
Runs the current app as a background app for the number of seconds requested. This is a synchronous method, it returns after the back has been returned to the foreground.

Parameters:
seconds - Number of seconds to run App in background

openNotifications

public void openNotifications()
Open the notification shade, on Android devices. Android only method.


performTouchAction

public TouchAction performTouchAction(TouchAction touchAction)
Performs a chain of touch actions, which together can be considered an entire gesture. See the Webriver 3 spec https://dvcs.w3.org/hg/webdriver/raw-file/default/webdriver-spec.html It's more convenient to call the perform() method of the TouchAction object itself.

Specified by:
performTouchAction in interface MobileDriver
Parameters:
touchAction - A TouchAction object, which contains a list of individual touch actions to perform
Returns:
the same touchaction object

performMultiTouchAction

public void performMultiTouchAction(MultiTouchAction multiAction)
Performs multiple TouchAction gestures at the same time, to simulate multiple fingers/touch inputs. See the Webriver 3 spec https://dvcs.w3.org/hg/webdriver/raw-file/default/webdriver-spec.html It's more convenient to call the perform() method of the MultiTouchAction object.

Specified by:
performMultiTouchAction in interface MobileDriver
Parameters:
multiAction - the MultiTouchAction object to perform.

tap

public void tap(int fingers,
                org.openqa.selenium.WebElement element,
                int duration)
Convenience method for tapping the center of an element on the screen

Parameters:
fingers - number of fingers/appendages to tap with
element - element to tap
duration - how long between pressing down, and lifting fingers/appendages

tap

public void tap(int fingers,
                int x,
                int y,
                int duration)
Convenience method for tapping a position on the screen

Parameters:
fingers - number of fingers/appendages to tap with
x - x coordinate
y - y coordinate
duration -

swipe

public void swipe(int startx,
                  int starty,
                  int endx,
                  int endy,
                  int duration)
Convenience method for swiping across the screen

Parameters:
startx - starting x coordinate
starty - starting y coordinate
endx - ending x coordinate
endy - ending y coordinate
duration - amount of time in milliseconds for the entire swipe action to take

pinch

public void pinch(org.openqa.selenium.WebElement el)
Convenience method for pinching an element on the screen. "pinching" refers to the action of two appendages pressing the screen and sliding towards each other. NOTE: This convenience method places the initial touches around the element, if this would happen to place one of them off the screen, appium with return an outOfBounds error. In this case, revert to using the MultiTouchAction api instead of this method.

Parameters:
el - The element to pinch

pinch

public void pinch(int x,
                  int y)
Convenience method for pinching an element on the screen. "pinching" refers to the action of two appendages pressing the screen and sliding towards each other. NOTE: This convenience method places the initial touches around the element at a distance, if this would happen to place one of them off the screen, appium will return an outOfBounds error. In this case, revert to using the MultiTouchAction api instead of this method.

Parameters:
x - x coordinate to terminate the pinch on
y - y coordinate to terminate the pinch on

zoom

public void zoom(org.openqa.selenium.WebElement el)
Convenience method for "zooming in" on an element on the screen. "zooming in" refers to the action of two appendages pressing the screen and sliding away from each other. NOTE: This convenience method slides touches away from the element, if this would happen to place one of them off the screen, appium will return an outOfBounds error. In this case, revert to using the MultiTouchAction api instead of this method.

Parameters:
el - The element to pinch

zoom

public void zoom(int x,
                 int y)
Convenience method for "zooming in" on an element on the screen. "zooming in" refers to the action of two appendages pressing the screen and sliding away from each other. NOTE: This convenience method slides touches away from the element, if this would happen to place one of them off the screen, appium will return an outOfBounds error. In this case, revert to using the MultiTouchAction api instead of this method.

Parameters:
x - x coordinate to start zoom on
y - y coordinate to start zoom on

getNamedTextField

public org.openqa.selenium.WebElement getNamedTextField(String name)
In iOS apps, named TextFields have the same accessibility Id as their containing TableElement. This is a convenience method for getting the named TextField, rather than its containing element.

Parameters:
name - accessiblity id of TextField
Returns:
The textfield with the given accessibility id

isAppInstalled

public boolean isAppInstalled(String bundleId)
Checks if an app is installed on the device

Parameters:
bundleId - bundleId of the app
Returns:
True if app is installed, false otherwise

installApp

public void installApp(String appPath)
Install an app on the mobile device

Parameters:
appPath - path to app to install

removeApp

public void removeApp(String bundleId)
Remove the specified app from the device (uninstall)

Parameters:
bundleId - the bunble identifier (or app id) of the app to remove

launchApp

public void launchApp()
Launch the app which was provided in the capabilities at session creation


closeApp

public void closeApp()
Close the app which was provided in the capabilities at session creation


endTestCoverage

public void endTestCoverage(String intent,
                            String path)
Get test-coverage data Android-only method

Parameters:
intent - intent to broadcast
path - path to .ec file

lockScreen

public void lockScreen(int seconds)
Lock the device (bring it to the lock screen) for a given number of seconds

Parameters:
seconds - number of seconds to lock the screen for

shake

public void shake()
Simulate shaking the device This is an iOS-only method


complexFind

public MobileElement complexFind(String complex)

scrollTo

public MobileElement scrollTo(String text)

scrollToExact

public MobileElement scrollToExact(String text)

context

public org.openqa.selenium.WebDriver context(String name)
Specified by:
context in interface org.openqa.selenium.ContextAware

getContextHandles

public Set<String> getContextHandles()
Specified by:
getContextHandles in interface org.openqa.selenium.ContextAware

getContext

public String getContext()
Specified by:
getContext in interface org.openqa.selenium.ContextAware

rotate

public void rotate(org.openqa.selenium.ScreenOrientation orientation)
Specified by:
rotate in interface org.openqa.selenium.Rotatable

getOrientation

public org.openqa.selenium.ScreenOrientation getOrientation()
Specified by:
getOrientation in interface org.openqa.selenium.Rotatable

findElementByIosUIAutomation

public org.openqa.selenium.WebElement findElementByIosUIAutomation(String using)
Specified by:
findElementByIosUIAutomation in interface FindsByIosUIAutomation

findElementsByIosUIAutomation

public List<org.openqa.selenium.WebElement> findElementsByIosUIAutomation(String using)
Specified by:
findElementsByIosUIAutomation in interface FindsByIosUIAutomation

findElementByAndroidUIAutomator

public org.openqa.selenium.WebElement findElementByAndroidUIAutomator(String using)
Specified by:
findElementByAndroidUIAutomator in interface FindsByAndroidUIAutomator

findElementsByAndroidUIAutomator

public List<org.openqa.selenium.WebElement> findElementsByAndroidUIAutomator(String using)
Specified by:
findElementsByAndroidUIAutomator in interface FindsByAndroidUIAutomator

findElementByAccessibilityId

public org.openqa.selenium.WebElement findElementByAccessibilityId(String using)
Specified by:
findElementByAccessibilityId in interface FindsByAccessibilityId

findElementsByAccessibilityId

public List<org.openqa.selenium.WebElement> findElementsByAccessibilityId(String using)
Specified by:
findElementsByAccessibilityId in interface FindsByAccessibilityId

getRemoteAddress

public URL getRemoteAddress()


Copyright © 2014. All rights reserved.