Driver code changes

The Sauce Labs Test Cloud is another Selenium Grid in the cloud. With that, it requires some changes to the Selenium Driver class that was built in this framework. The types of changes required are for the remote hub URL, the sauce-specific desired capabilities, and any browser or mobile device options to set up the driver.

Here are a few code samples of some of the changes that would go into an environment section of the driver class called saucelabs instead of local or remote:

// section in CreateDriver.java class for saucelabs URL

String remoteHubURL = null;
String SAUCE_USERNAME = "xyz";
String SAUCE_ACCESS_KEY = "XYZ";

if
( environment.equalsIgnoreCase("saucelabs") ) {
if ( System.getenv("SAUCE_USERNAME") != null &&
System.getenv("SAUCE_ACCESS_KEY") != null ) {

remoteHubURL = "http://" + System.getenv("SAUCE_USERNAME") +
":" +
System.getenv("SAUCE_ACCESS_KEY") +
"@ondemand.saucelabs.com:80/wd/hub";
}

else {
remoteHubURL = "http://[SAUCE_USERNAME]:[SAUCE_ACCESS_KEY]@" +
"ondemand.saucelabs.com:80/wd/hub";
}
}

// section in CreateDriver.java class for saucelabs display

if ( platform.toLowerCase().contains("mac") ||
platform.toLowerCase().contains("os x") ) {

caps.setCapability("screenResolution", "1920x1440");
}

else {
caps.setCapability("screenResolution", "2560x1600");
}

// section in CreateDriver.java class for saucelabs platform

if ( System.getenv("SELENIUM_PLATFORM") != null ) {
caps.setCapability("platform",
System.getenv("SELENIUM_PLATFORM"));
}

// section in CreateDriver.java class for saucelabs features

...

caps.setCapability("build", System.getProperty("BUILD_NUMBER"));
caps.setCapability("maxDuration", 10800);
caps.setCapability("commandTimeout", 300);
caps.setCapability("idleTimeout", 300);
caps.setCapability("tags", platform + "," + browser + "," + "62.0");

if
( System.getProperty("RECORDING").equalsIgnoreCase("true") ) {
caps.setCapability("recordVideo", true);
caps.setCapability("videoUploadOnPass", true);
caps.setCapability("recordScreenshots", true);
caps.setCapability("recordLogs", true);
}

if
( System.getenv("TUNNEL_IDENTIFIER") != null ) {
caps.setCapability("tunnelIdentifier",
System.getenv("TUNNEL_IDENTIFIER"));
}

....

These are a few of the driver class capabilities that would be required, but as you can see, this follows the same approach to setting them using an in-house grid. Sauce Labs has a list of dozens of capabilities that can be set for both the browser and mobile device platforms. Notice in these examples, all the System.getenv() method calls are retrieving environment variables set by the Sauce Labs Jenkins plugin.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.222.47