Integrate your Selenium Automation project with SauceLabs

Rochelle Abeywickrama
4 min readMay 28, 2020

Today’s usage of applications on multiple browsers is quite high, hence it is important to verify that the applications we develop are compatible with the platforms, browsers, and their versions.

Think of a practical scenario — we are about to launch a new software product / a feature implementation / an enhancement or it can be a bug fix…

  • What if it doesn’t support a specific platform/browser/version?
  • What if one of the workflows breaks in a specific combination?
  • Maybe the latest browser release will not support your product?

This is where ‘compatibility testing’ comes to the picture.

What is Compatibility testing?

It is a non-functional test to ensure the satisfaction of the customers. It’s about determining if your software application or product is capable of running in different browsers, databases, hardware, operating system, mobile devices, and networks, etc.

Out of the types of compatibility testing, ‘Browser Compatibility’ has become very popular. The most popular browsers in the present are — Firefox, Chrome, Internet Explorer, Safari, MS Edge, Opera, etc.

However, it would be a strain on every individual to manage testing for all browsers, operating systems, and versions. It is also an unnecessary expense to corporate management and a huge burden. Today’s advanced technologies have developed cross-browser tools such as — SauceLabs, BrowserStack, LambdaTest, etc. So, why not integrating our automation test suite with a cloud solution as such?

SauceLabs is one of the most comprehensive cross-browser continuous testing cloud which provides comprehensive coverage of OS/Browser combinations, extended debugging and securely test local apps.

Why SauceLabs?

Pros;

  • It supports Java, C#, Python, Ruby, and JavaScript.
  • Automatically records a video of cloud testing.
  • Supports parallel execution.
  • Variety of platforms.
  • No need for a dedicated person to check test infrastructure and maintain.
  • Ability to provide access to the whole team.

Cons;

  • Not a free tool.
  • VM sometimes has mouse pointer active and some OS system windows.
  • Troubleshooting test infrastructure environment.

Having said that, let’s get started...

What you’ll need?

  • Need to have a SauceLabs account
  • The URL of the datacenter
  • Username and the access key — you can find under User Profile > User Settings
  • Executable Selenium automation project which can run locally (or remotely on a Selenium grid or other service)
  • The web application for testing — located on a public internet where virtual machines can access.

A Few code changes to your project…

In your BaseTest,

public static final String USERNAME = “<user name>”; 
public static final String ACCESS_KEY = “<access key>”;
  • Initialize DesiredCapabilities and create a separate method.
public static final DesiredCapabilities CAPABILITIES = new DesiredCapabilities();
  • In the method where the WebDriver invokes, add the RemoteWebDriver Connection
driver = new RemoteWebDriver(new URL("https://ondemand.saucelabs.com/wd/hub"), CAPABILITIES);
  • Create a DataProvider with all the expected OS/Browser/Version combinations — for this, you can also add a separate Excel file and implement an Excel file reader method instead.
  • Externalize the data center endpoint and test application URL and update the method where the web driver invokes.
String sauceURL = "https://ondemand.saucelabs.com/wd/hub";
String launchURL = "https://the-internet.herokuapp.com/";
  • In the @AfterMethod, add a javascript executor to publish the test results to the SauceLabs dashboard.

In the Test Scripts, update the test case binding the data provider.

Verify the Remote Connection

  • Go to your Automation Test Script and hit ‘Run’
  • Login to SauceLabs
  • Navigate to Automated > Test Results
  • Check the SauceLabs Test Results dashboard-if the configuration is successful, you will see your test will display in running mode.
Past and present test executions should be available in this view
  • Each test combination should execute without manual intervention.
  • By clicking on the running job link — you’re able to check the live video of the execution.
Live video, commands executed, OS and Browser combination details are visible
  • Also, under Automation > Builds — you’re able to see the executions under each build.
In this view, the build history and the pass/fail statuses will be reflected with execution time duration

If one / more tests are failed in a build, it will be marked as ‘Build failed’

Failed tests will turn to red — by clicking on the test name, you can view the failed steps
You can investigate the failure by expanding the failed step

You can also see the job execution status in your IDE console.

IntelliJ Console view during / on completion of a build

Analyzing Test Results

Navigate to Insights > Test Overview and you’ll see the below dashboard.

Snapshots and Test Summary views
Test Breakdown

This is it! :)

If you have any trouble — please visit my GitHub repository. I hope this will be helpful for your projects to reduce the effort of compatibility testing.

Hoping to see you’ll with another experiment and thank you for reading.

Till then... Happy Automating!!!

--

--

Rochelle Abeywickrama

Associate Lead Quality Engineering at SyscoLABS | MSc in IT | BSc in IT | ISTQB — CTFL | ISTQB — CTAL (ATM) | SAFe Agilist, Certified Scrum Master