When adding support to the driver class for third-party grids such as Sauce Labs or Perfecto Mobile, users must add conditions in the driver class that set specific preferences, credentials, URLs, and so on, to direct traffic to that test platform. They are really just other Selenium grids to run against in the cloud, which free up the tester from all the maintenance requirements of an in-house grid. The condition to run on one of these third-party platforms can be passed as a parameter to the test, specifically environment. For instance, here is an example of a TestNG XML file using parameters to set up the driver:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="My Test Suite" preserve-order="true" parallel="false" thread-count="1" verbose="2">
<!-- suite parameters -->
<!-- "local", "remote", "saucelabs" -->
<parameter name="environment" value="saucelabs" />
<test name="My Feature Test">
<!-- test parameters -->
<parameter name="browser" value="chrome" />
<parameter name="platform" value="Windows 10" />
or
<parameter name="browser" value="iphone"/>
<parameter name="platform" value="iphone"/>
<classes>
<class name="com.myproject.MyTest" />
</classes>
</test>
</suite>
Each provider will require a different RemoteWebDriver URL, credentials to access their test cloud, preferences, and various other features that would allow access to a DMZ inside a corporate Firewall. Here are some examples of specific Sauce Labs Cloud platform requirements:
- Tunnel: If the web server, or any other servers, are behind a corporate Firewall and not open to the internet, then a unique tunnel will have to be set up and passed to the driver class as a Desired Capability.
- Remote URL: Sauce Labs has its own RemoteWebDriver URL for accessing its server at http://SAUCE_USERNAME:[email protected]:80/wd/hub.
- Preferences: Sauce Labs has a set of unique capabilities that allow the passing of when creating the driver for the test. Examples include screen resolution, browser versions (including latest and beta versions), mobile device types (including physical and simulator/emulator devices), Selenium versions, driver versions, session parameters, results processing, and so on.
// third party preferences for SauceLabs...
if ( environment.equalsIgnoreCase("saucelabs") ) {
// setup the Selenium Grid capabilities...
String remoteHubURL =
"http://SAUCE_USERNAME:SAUCE_ACCESS_KEY
@ondemand.saucelabs.com:80/wd/hub";
caps.setCapability("screenResolution",
"1920x1080");
caps.setCapability("recordVideo",
false);
caps.setCapability("tunnelIdentifier",
System.getProperty("TUNNEL_IDENTIFIER"));
...
}