WebDriver Commands and Functions for Mobile Device Testing
You can use WebDriver commands and functions to automate both iOS and Android mobile devices. If this is your first time automating mobile devices, please refer to Connecting to Mobile Devices for important information regarding automation of mobile devices with Eggplant Functional.
You must have Faster Screen Updates enabled in order to accurately click WebElements when doing WebDriver testing on iOS devices.
In mobile WebDriver testing, connections are made to a specific app rather than to a browser on your system under test (SUT). Testing with WebDriver is based around interacting with various elements in the app you're testing.
WebElement Identifiers
To access a WebElement within the app you're testing, such as when using the FindElement()
function or the Click
command with a WebDriver connection, you must specify the element you want to interact with. The following WebElement Identifiers can be used to locate elements on a mobile device:
- webID: Use this property to locate an element by the value of its ID attribute.
- webName: Use this property to locate an element by the value of its Name attribute.
- webClassName: Use this property to locate an element by the value of its Class attribute.
- webXPath: Use this property to locate an element by using an XPath expression. For information about XPath and XPath expressions, see XPath in Selenium WebDriver: Complete Tutorial.
- webAccessibilityID: Use this property to locate an element by the value of its Accessibility ID attribute.
WebConnect
Command
- This topic explains the use of the
WebConnect
command for mobile WebDriver connections. For information about using this command for browser-based WebDriver connections, see WebDriver Actions: WebConnect Command. - If you are using a Sauce Labs connection, the WebConnect command is not supported because Eggplant Functional automatically opens a WebDriver connection to those devices when you establish the connection. Instead of using the
WebConnect
command, you should use theConnect
command. If you attempt to use theWebConnect
command to establish a Sauce Labs connection, you will receive an error when you try to open the WebDriver connection. - If you are using Mobile Device Connections, the WebConnect command is supported, but not recommended. Eggplant Functional automatically opens a WebDriver connection when you establish the Mobile Device Connection. Using WebConnect in the context of a Mobile Device Connection is considered to be an advanced use-case and is outside the scope of this document.
Behavior: This command makes a connection to a specified app on a mobile device.
Parameters: The WebConnect
command can take the following parameters:
browser:
Optional.host
: Required. For mobile device connections, this is alwayslocalhost
.port
: Required. The port number over which to create a mobile WebDriver connection. The default port for iOS connections is 8100. The default port for Android connections is 4723.name:
Optional. A name to use for referring to this connection. This is the name that appears in the Eggplant Functional Connection List. If this is specified, the script will pull thebrowser
,host
,port
, andplatformName
(if mobile) for that connection. Any of those properties provided to theWebConnect
command will override those set in the Connection List. If no connection with the specified name exists in the Eggplant Functional Connection List, then a new connection will be created and saved with the information provided.platformName:
Mobile Only. Required. The operating system of the mobile device.bundleId:
iOS only. Required. The identifier of the mobile app you want to open and test. This parameter is case-sensitive.device:
Android only. Required. The ID number of the device. This can be found by enteringadb devices
in the command line.appPackage:
Android only. Required. The identifier of the mobile app you want to open and test. This parameter is case-sensitive.appActivity:
Android only. Required. The screen in the app that you want the app to open on. This parameter is case-sensitive.automationName:
Android only. Required. The automation engine to use to test the device.
Syntax:
WebConnect connectionProperties
connectionProperties can include: browser:browserName, {host:hostAddress,} {port:portName,} {url:pageURL,} {name:connectionName,} {desiredCapabilities:{capabilitiesPropertyList}} {platformName: NameofPlatform,} {bundleId: bundleIDNumber}
In the case of desiredCapabilities
, the curly braces are a part of the required syntax, as they are used when communicating with SauceLabs connections.
Example:
WebConnect host:"localhost", port:"8100", platformName: "iOS", bundleId: "com.apple.Maps"