WebDriver Actions
When writing SenseTalk scripts for testing based on Selenium WebDriver connections, you use WebDriver actions to connect to web browsers or mobile devices, navigate through the pages or mobile apps included in your tests, and perform actions on these pages or apps. SenseTalk includes several commands and functions that let you perform such actions on the web pages being tested.
WebDriver Connections
To use WebDriver actions, you must create an active connection to a web browser. The type of the connection depends on whether you plan to self-host your browsers on your IT infrastructure or whether you plan to use Sauce Labs browser-as-a-service infrastructure.
If you plan to self-host your browsers, you need to use Eggplant Functional's explicit WebDriver connection. A WebDriver connection is similar to the VNC or RDP connection you use for image-based scripting with Eggplant Functional. There are several ways to create a WebDriver connection:
- Use the WebConnect Command.
- Use the WebDriver Function.
- Configure a WebDriver connection through the Connection List in Eggplant Functional.
If you plan to utilize Sauce Labs connections, you should understand that a single Sauce Labs connection logically exposes both a VNC connection and a WebDriver connection. The WebDriver connection is created automatically when the Sauce Labs connection is created and it cannot be managed independently of the VNC connection. Hence, the WebConnect command cannot be used to manage a Sauce Labs connection.
There are several ways to create a Sauce Labs connection:
- Use the Connect Command.
- Configure a the connection through the Connection List in Eggplant Functional.
Once you have a Sauce Labs connection, you can send the Sauce Labs connection WebDriver commands using the exact same syntax as you would for an explicit WebDriver connection.
WebDriverConnection Object Properties
When you create a connection to a web browser by using one of the above approaches, SenseTalk creates a WebDriverConnection object that has a number of properties that provide information about the connection. The following list shows the WebDriverConnection object properties:
-
url: The URL of the page that is currently displayed in the browser. Setting the URL property of a WebDriverConnection object tells the browser to navigate to the specified URL.
-
title: The title (i.e., the value of the Title tag) of the page that is currently displayed in the browser. You cannot change this property.
-
pageSource: The entire HTML source of the page that is currently displayed in the browser. You cannot change this property.
-
alertText: The text of an alert message, if any, that is currently displayed in the browser. You cannot change this property.
-
activeElement: This property is a WebElement object for the active element in the browser. For information about the properties that might be returned, see WebElement Objects. You cannot change this property.
-
cookies: A list of all the cookies associated with the page that is currently displayed in the browser. Each cookie is a property list that includes
name
,value
, and other properties associated with the cookie.You can review the cookies contained in the property:
put the webdriver's cookies // Displays all the cookies
put each item of the webdriver's cookies whose domain is ".testplant.com" // Displays only the specified cookiesYou can add cookies to the list. When adding cookies, you must provide a name and value:
insert (Name:"addition1", value:"my secret stuff") into the webdriver's cookies
You can delete cookies from the list:
set the webdriver's cookies to each item of the webdriver's cookies whose domain is not ".testplant.com" // Deletes cookies with a domain other than .testplant.com
set the webdriver's cookies to empty // Deletes all cookies -
windowHandle: This property is a unique identifier for the current browser window. When the browser has more than one window, you can set the
windowHandle
property to a different value to switch the window focus. -
allWindowHandles: This list shows a unique
windowHandle
identifier for each of the windows that are open in the browser. Use these identifiers to set thewindowHandle
property to switch focus to a different window. You cannot change this property. -
windowRectangle (or windowRect): The rectangle (x1, y1, x2, y2) of the current browser window. Setting the
windowRectangle
property changes the size and location of the window. -
windowSize: The size (width, height) of the current browser window. Setting the
windowSize
property changes the size of the window. You can change the browser window size by setting the width and height or by usingmax
to maximize the browser size.set the webdriver's windowsize to "500, 1000"
set the webdriver's windowsize to "max" -
windowOrigin (or windowLocation): The coordinates (x, y) of the origin (top-left corner) of the current browser window. Setting the
windowOrigin
property changes the location of the window on the screen. -
geoLocation: A property list with latitude, longitude, and optional altitude properties that represent the geolocation of the browser. For example:
(altitude:"value", latitude:"value", longitude:"value")
You can use this property to set the browser's geolocation:
set the webdriver's geoLocation to (altitude: 42,latitude:33.8099601,longitude:-117.91554840000003)
Note that not all websites leverage browser geolocation for localization.
-
capabilities: A property list of the specific capabilities available through this WebDriver connection. You cannot change the values contained in this property list.
先端Although you can request desired capabilities through the
WebConnect
command orWebDriver()
function when initially opening a connection, the browser might not honor such requests. Therefore, it can be useful to request theCapabilities
property list after you establish the connection if you need to be certain of the actual capabilities:log the webdriver's capabilities
-
name: The user-assigned name of this WebDriver connection. You can specify this value when creating a WebDriver connection through the Connection List, or by using the
name
property when using theWebConnect
command or theWebDriver
function to open a connection. You cannot change this property after opening the WebDriver connection. -
browser: The browser name you specify when creating a WebDriver connection through the Connection List, or with the
browser
property when using theWebConnect
command or theWebDriver
function to open a WebDriver connection. You cannot change this property after opening the WebDriver connection. -
host: The host machine where the WebDriver server is running. You cannot change this property.
-
port: The number of the port on which this WebDriver connection is communicating with the server. You cannot change this property.
WebConnect
Command
This code definition explains the use of the WebConnect
command for use with browsers. For information about using this command for mobile, see .WebDriver Commands and Functions for Mobile Device Testing.
If you are trying to set up a connection to a Sauce Labs browser to use for WebDriver testing, you must use the Connect Command.
When a connection is made to Sauce Labs through Eggplant functional, the Connect command establishes both a VNC connection and a WebDriver connection. You can send WebDriver commands directly to the Sauce Labs connection just as you would an explicit WebDriver connection.
Behavior: This command makes a connection to a web browser. You specify the connection by providing a server's IP address (host
) and browser name (browser
), or you can call a defined WebDriver connection by name from the Eggplant Functional Connection List. If Selenium is using a non-standard port, the port
must be specified as well.
If there is no matching entry in the Connection List when you run the WebConnect
command, Eggplant Functional adds a temporary entry to the Connection List for the connection. If a connection to that browser is already open, it is made the active WebDriver connection.
Parameters: The WebConnect
command can take the following parameters:
browser
:Required.
The name of the browser you want to connect to. This parameter is not required when usingWebConnect
for mobile testing.
You can use any browser supported by Selenium Server 2.0. Typically, you need to install a driver for each browser type you want to use. See Selenium WebDriver Testing with Eggplant Functional for information about installing the Selenium server and browser drivers.
-
host
:Required.
A server's IP address or hostname, or the name of a WebDriver connection from the Eggplant Functional Connection List. If no host is specified, the command attempts to connect to the same host as the current VNC or RDP SUT connection. If no SUT connection is available, the command fails without a specified host. -
url
:Optional.
A URL for a web page you want to open in the browser. -
port
:Optional; defaults to 4444.
The port number over which to connect. Must be specified if a different port is being used. -
name
:Optional.
A name to use for referring to this connection. If specified, this is the name that appears in the Connection List. -
desiredCapabilities
:Optional.
Takes a property list to request desired capabilities of the WebDriver connection, which can affect the behavior or appearance of the web browser. Capability names that you can specify include but are not limited to:acceptSslCerts
,applicationCacheEnabled
,browserConnectionEnabled
,cssSelectorsEnabled
,databaseEnabled
,handlesAlerts
,javascriptEnabled
,locationContextEnabled
,nativeEvents
,rotatable
,takesScreenShot
, andwebStorageEnabled
.Any of the desired capabilities values can be set as a Boolean, true/false, and you can include as many of them as you need. However, the WebDriver might not respect a given request. The capabilities supported depend on the driver and browser being used.
** If connecting to Selenium servers in SauceLabs environments,the username
and accessKey
are required. Pass the username
and accessKey
as desiredCapabilities
, like this:
desiredCapabilities: {username:"sauce_username", accessKey:"sauce_accessKey"}
(Alternately, Eggplant recommends that you utilize an explicit Sauce Labs connection, introduced in Eggplant Functional version 22.3, to get a webdriver connection to Sauce Labs. Eggplant Functional is able to store Sauce Labs credentials securely, providing enhanced security over using Capabilities. Please refer to the documentation for the Connect
Command for more information on creating Sauce Labs connections via SenseTalk.)
Syntax:
WebConnect connectionProperties
connectionProperties can include: browser:browserName, {host:hostAddress,} {port:portName,} {url:pageURL,} {name:connectionName,} {desiredCapabilities:{capabilitiesPropertyList}}
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:"192.168.199.132", browser: "chrome", port: "4444", name: "Connection2", url: "http://testplant.com"
Example:
WebConnect "WindowsChrome" // Connects to a pre-configured WebDriver connection named 'WindowsChrome' in the Connection List