Sample project to demonstrate the use of SauceLabs platform to run automated tests in remote browser sessions. This project / test suite uses Selenium + TestNG
No additional dependencies specific to SauceLabs need to be added in pom.xml
Capabilities / BrowserOptions need to be added inorder to run the tests in LambdaTest Browsers. Use SauceLabs Platform Configurator to generate the same for your required platform / browsers versions
- Sample code for Chrome latest (I am sending the credentials as Parameters and storing them in
TestParameters.sl_username
,TestParameters.sl_accessKey
. U may do the same or hardcode it in the below code.)
ChromeOptions browserOptions = new ChromeOptions();
browserOptions.setPlatformName("Windows 11");
browserOptions.setBrowserVersion("latest");
Map<String, Object> sauceOptions = new HashMap<>();
sauceOptions.put("username", TestParameters.sl_username);
sauceOptions.put("accessKey", TestParameters.sl_accessKey);
sauceOptions.put("build", "selenium-build-"+System.currentTimeMillis());
sauceOptions.put("name", "SauceLabsTest");
browserOptions.setCapability("sauce:options", sauceOptions);
- Initialize the driver
URL url = new URL("https://ondemand.us-west-1.saucelabs.com:443/wd/hub");
driver = new RemoteWebDriver(url, browserOptions);
-
If you would like to pass your SauceLabs credentials during runtime rather than hardcoding it, you can follow the below options:
-
As TestNG parameters
<parameter name="SLusername" value="YOUR_USERNAME" />
<parameter name="SLaccessKey" value="YOUR_ACCESSKEY" />
- As System Properties
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemProperties>
<property>
<name>SLusername</name>
<value>${SLusername}</value>
</property>
<property>
<name>SLaccessKey</name>
<value>${SLaccessKey}</value>
</property>
</systemProperties>
</configuration>
</plugin>
- In this case, you will only be able to trigger the test from CLI
mvn clean test -DSLusername=YOUR_USERNAME -DSLaccessKey=YOUR_ACCESSKEY
You will be able to view the Test Build progress and results from the SauceLabs Dashboard.
- Log in to your SauceLabs account
- Navigate to Automated > Test Results.
And you will be able to view the In Progress as well as Completed tests and their details including step wise logs and execution video.
Click on one of the builds and you will be able to see a detailed view of the test execution