WebDriver Commands and Functions for Mobile Device Testing

You can use WebDriver commands and functions to automate both iOS and Android mobile devices. The free iOS Gateway is required to automate iOS devices. For Android testing, you'll need Appium server and a few other components.

New Feature: Mobile WebDriver testing is available in Eggplant Functional 18.1.2 and later. WebDriver testing of iOS devices requires and iOS Gateway 5.1.2 and later.

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

Note: This code definition 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.

Behavior: This command makes a connection to a specified app on a mobile device.

Parameters: The WebConnect command can take the following parameters:

  • host: (Required) For mobile device connections, this is always localhost.
  • 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. If specified, this is the name that appears in the Connection List.
  • platformName: (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 entering adb 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 host: "hostAddress", port: "port", {name: "connectionName"} {, platformName: "value"} {, bundleId: "value"} {, device: "value"} {, appPackage: "value"} {, appActivity: "value"} {, automationName: "value"}

例:

WebConnect host:"localhost", port:"8100", platformName: "iOS", bundleId: "com.apple.Maps"

例:

WebConnect host: "localhost", port: "4723", platformName: "Android", device: "04157df49c1d0533", deviceName: "Android", appPackage: "com.google.android.apps.maps", appActivity: "com.google.android.maps.MapsActivity", automationName: "UIAutomator2"

WebDisconnect Command

Note: This code definition explains the use of the WebDisconnect command for mobile WebDriver connections. For information about using this command for browser-based WebDriver connections, see WebDriver Actions: WebDisconnect Command.

Behavior: This command disconnects WebDriver connections.

Parameters: None, a connection name, or All. If you do not specify any parameters, the active WebDriver disconnects. Use WebDisconnect with a specific connection name to close that connection, or use All to close all active connections.

Syntax:

WebDisconnect {connectionName | All}

例:

WebDisconnect // Disconnects the active WebDriver connection

例:

WebDisconnect All // Disconnects all WebDriver connections

例:

webDisconnect "iphone7"// Disconnects the WebDriver connection named "iphone7"

WebDriver() Function

Note: This code definition explains the use of the WebDriver() function for mobile WebDriver connections. For information about using this function for browser-based WebDriver connections, see WebDriver Actions: WebDriver() Function.

Behavior: By default, the function returns properties for the active WebDriver connection (if there is one). You can include parameters as specified below to switch to a different open connection (if available) or open a new connection.

When opening a new connection or switching the active connection, the WebDriver() function performs the same actions as the WebConnect command.

Parameters: The WebDriver() function can take the following parameters:

  • host: (Required) For mobile device connections, this is always localhost.
  • 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. If specified, this is the name that appears in the Connection List.

  • platformName: (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 entering adb 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:

WebDriver (host: hostAddress, port: port, {name: "connectionName"} {, name: "value"} {, platformName: "value"} {, bundleId: "value"} {, device: "value"} {, appPackage: "value"} {, appActivity: "value"} {, automationName: "value"} )

Returns: If you call the WebDriver() function without parameters, it returns the WebDriverConnection object of the active WebDriver connection.

If you open a WebDriver connection with the WebDriver() function, it returns the WebDriverConnection object for the newly created WebDriver connection.

例:

put WebDriver() // Returns information about the active WebDriver connection: <WebDriverConnection with Name:"iphone6plus", PlatformName:"iOS", Host:"localhost", BundleID:"com.testplant.YetAnotherSampleApp">

例:

set driver to WebDriver(host:"localhost", port: "8100", platformName: "iOS", bundleId: "com.testplant.YetAnotherSampleApp")

例:

set driver to WebDriver(host: "localhost", port: "4723", platformName: "Android", appPackage:"com.google.android.apps.maps", appActivity:"com.google.android.maps.MapsActivity", automationName:"UIAutomator2")

FindElement() Function

Note: This code definition explains the use of the FindElement() function for mobile WebDriver connections. For information about using this function for browser-based WebDriver connections, see Finding WebElements: FindElement() Function.

Behavior: This command locates a specific WebElement that you can interact with.

Parameters: The WebElement Identifier of the element that you want to find.

Syntax:

FindElement (IdentifierType: "Value")

例:

set textField to findElement (webName: "Enter Text Field") // Creates the variable textField containing the element with the WebName "Enter Text Field"

SwipeDown, SwipeLeft, SwipeRight, SwipeUp commands

Note: This code definition explains the use of the Swipe commands for mobile WebDriver connections. For information about using this function for other mobile connections, see Mobile Control and Touch Events: Swipe Commands.

Behavior: These commands execute a directional swipe on the specified element.

Parameters: The WebElement Identifier of the element to execute the swipe on.

Syntax:

SwipeDown (identifierType: "value")

SwipeDown (identifierType: "value")

SwipeLeft (identifierType: "value")

SwipeRight (identifierType: "value")

例:

SwipeUp (webClassName: "XCUIElementTypeMap")

ClearKeys Command

Note: This code definition explains the use of the ClearKeys command for mobile WebDriver connections. For information about using this function for browser-based WebDriver connections, see WebDriver Mouse and Keyboard Events: ClearKeys Command.

Behavior: This command clears the text entered in the specified WebElement.

Parameters: The WebElement Identifier of the element to clear.

Syntax:

ClearKeys (identifierType: "value")

例:

ClearKeys (webName: "Enter Text Field") // Clears text from the element with the webName "Enter Text Field"

例:

set textField to findElement(webName: "Enter Text Field") // Puts the name of a WebElement into a variable

ClearKeys textField // Clears text from the WebElement

SendKeys Command

Note: This code definition explains the use of the SendKeys command for mobile WebDriver connections. For information about using this function for browser-based WebDriver connections, see WebDriver Mouse and Keyboard Events: SendKeys Command.

Behavior: This command sends keystrokes to an element on the mobile device.

Parameters: A text string enclosed in quotation marks. If you need to include quote characters in your text string, you can enclose the text in double angle brackets (<<>>).

Syntax:

SendKeys {"text" | <<text>>}

例:

SendKeys "Hello World!" // Sends text to the active element

例:

set textField to findElement (webName: "Enter Text Field") // Puts the name of a WebElement into a variable

SendKeys textField, "A nod's as good as a wink to a blind bat" // Uses the variable to make the WebElement active, then sends the keystrokes to type: "A nod's as good as a wink to a blind bat"

Tap Command

Note: This code definition explains the use of the Tap command for mobile WebDriver connections. For information about using this function for other mobile connections, see Mobile Control and Touch Events: Tap Command.

Behavior: The Tap command locates an element within the DOM and simulates a tap event at the found location.

Parameters: The WebElement Identifier of the element to tap.

Syntax:

Tap (identifierType: "value")

例:

Tap (webName: "Map") // Locates the "Map" element and executes a tap

DoubleTap Command

Note: This code definition explains the use of the DoubleTap command for mobile WebDriver connections. For information about using this function for other mobile connections, see Mobile Control and Touch Events: DoubleTap Command.

Behavior: The DoubleTap command locates an element within the DOM and simulates a double-tap event at the found location.

Parameters: The WebElement Identifier of the element to double-tap.

Syntax:

DoubleTap (identifierType: "value")

例:

DoubleTap (webClassName: "XCUIElementTypeMap") // Locates the element with class name "XCUIElementTypeMap" and executes a double-tap

WebScreenshot Command

Note: This code definition explains the use of the WebScreenshot command for mobile WebDriver connections. For information about using this function for browser-based WebDriver connections, see WebDriver Actions: WebScreenshot Command.

Behavior: This command takes a screenshot of the mobile device with the active WebDriver connection and saves it according to the specified file name or full file path.

Parameters: A required file name that can optionally include the full file path of the desired save location. If no file path is included in the filename parameter, the screenshot is saved into the user's documents directory.

Syntax:

WebScreenshot {"webDriverName",} "fileName"

例:

WebScreenshot "shot1" // Captures a WebDriver screenshot for the active WebDriverConnection and saves it with the name 'shot1'

例:

WebScreenshot "/Users/admin/Desktop/shot5" // Saves a screenshot to the Desktop with name 'shot5'

GetDeviceOrientation() Function

Note: This code definition explains the use of the GetDeviceOrientation() function for mobile WebDriver connections. For information about using this function for other mobile connections, see Mobile SUT Information: GetDeviceOrientation Function.

Behavior: This function returns the current rotation of the screen of the device with the active WebDriver connection.

パラメータ:なし。

Syntax:

GetDeviceOrientation()

Returns: The possible values are the same as the parameters for the setDeviceOrientation command: Landscape, LandscapeRight, Portrait, PortraitUpsideDown.

例:

put GetDeviceOrientation() // Returns the orientation of the device screen

例:

put "Device rotated to " & GetDeviceOrientation() // Returns "Device rotated to" the orientation of the device screen

Related:

SetDeviceOrientation Command

Note: This code definition explains the use of the SetDeviceOrientation command for mobile WebDriver connections. For information about using this function for other mobile connections, see Mobile Control and Touch Events: SetDeviceOrientation Command.

Behavior: Changes the orientation of the device with the active WebDriver connection to what you specify with the parameter. The different orientations work only if the active app and operating system support them.

Parameters: The device orientation that you want to set. Options are Portrait, PortraitUpsideDown, Landscape, LandscapeRight. Note that Android devices accept only Portrait and Landscape. If the requested orientation isn't supported by the operating system or app, no error is returned and the screen remains in its previous orientation.

Syntax:

SetDeviceOrientation value

例:

SetDeviceOrientation LandscapeRight

Related:

 

This topic was last updated on 2月 01, 2019, at 11:13:23 午前.

Eggplant icon Eggplant.io | Documentation Home | User Forums | Support | Copyright © 2019 Eggplant