Remote Test Execution with Selenium and Sauce Labs
By: Ranorex Webtestit
Tags: Selenium, Webtestit, Testing, Test Automation, Sauce Labs

Remote Test Execution with Selenium and Sauce Labs

Remote test execution speeds up the testing process and ensures consistent coverage and maintenance of your tests. Sauce Labs is one of the solutions that stands out when it comes to the execution of Selenium scripts in remotely placed endpoints. Ranorex Webtestit Follow May 27, 2019 · 6 min read

Remote test execution means using remote machines to run tests simultaneously and execute them across different test environments, i.e. different operating systems, browsers, system configurations, etc.

In contrast to running tests on a local machine, remote test execution — as its name suggests — requires a remote execution environment.

The principal advantage of this approach is the ability to perform execution of test automation on multiple remote machines as well as multiple browsers at the same time. This is particularly useful in a distributed environment when you have to execute hundreds or even thousands of tests on a regular basis.

Executing tests on multiple machines and browsers doesn’t only save time but ensures better coverage as well.

Running tests on local machines, however, shouldn’t be completely tossed out because of all of the advantages of remote test execution. Some types of tests benefit more from being run on a local machine, allowing testers to have a look at the SUT and debug tests at the time of testing, rather than having to guess what went wrong based on screenshots or videos. Also, some testers don’t have projects big enough to justify the need for the remote test execution on multiple machines. However, if the scope of a project expands, executing all test cases using one system could become more difficult.

For example, what would happen if you need to check things on multiple browser and OS combinations?

This is where remote test execution comes into play. Rather than set up a costly test infrastructure that you need to run and maintain on your own, you can easily outsource things to someone else’s grid, preferably to one located in the cloud.

One of the most popular tools/solutions among developers and testers who need to execute multiple tests across different browsers and operating systems is Sauce Labs.

What is Sauce Labs?

Sauce Labs is a cloud-based platform for manual and automated testing of web and mobile applications. Sauce Labs allows users to run automated and manual tests in the cloud on hundreds of different browser, operating system, and device combinations, using several testing frameworks.

There are various reasons why testers choose Sauce Labs for manual and automated testing:

Speed — Speed is the most important reason to move the testing to the cloud. Cloud-based software tests, such as those in Sauce Labs reduce overall testing time because of the possibility to run tests in parallel

— Speed is the most important reason to move the testing to the cloud. Cloud-based software tests, such as those in Sauce Labs reduce overall testing time because of the possibility to run tests in parallel Better coverage — Sauce Labs improves the quality of testing with better browser coverage and compatibility

— Sauce Labs improves the quality of testing with better browser coverage and compatibility Better maintenance — Sauce Labs could-based solution also resolves some of the maintenance issues present with other solutions, such as Selenium Grid

Imagine finding yourself in the familiar scenario in which you need to test all your test cases in various versions of browsers, as well as various platforms. You’ll agree that one cannot simply install all that stuff in their local box/environment.

Now, this is where Sauce Labs comes in handy, allowing you to focus on testing rather than be worried about maintaining a bunch of environments against which your tests need to run.

Sauce Labs supports running automated tests with Selenium WebDriver (for web applications) and Appium (for native and mobile web applications). In this article, we will focus on using Sauce Labs as your remote execution provider.

Integrating Sauce Labs and Selenium

To start integrating your Selenium test scripts with Sauce Labs, you need to have a Sauce Labs account. You can sign up for a free 14-day trial.

The username you’ve chosen when you created your Sauce Labs account will be used in your test scripts, as well as your access key. To find your access key, do the following:

Click your name in the Account Profile menu in the upper-right corner Click User Settings Scroll down to Access Key

Note: You may need to enter your Sauce Labs password to view the access key

Finally, click the Copy icon.

You’ll find both username and access key in your code, looking like this:

SAUCE_USERNAME and SAUCE_ACCESS_KEY

You’ll need to replace these with your actual credentials.

Next, you should have a Selenium environment with the Java bindings set up on a local machine where you’re running your tests. From now on, the integration is quite simple, as the only piece of code you have to update is the one allowing you to fetch the Selenium driver.

Here’s what it would look like in Java:

WebDriver driver = new RemoteWebDriver(new URL(“http://YOUR_USERNAME:YOUR_ACCESS_KEY@ondemand.saucelabs.com:80/wd/hub");

You’ve probably noticed that this piece of code invokes no browser. For someone who is accustomed to using WebDriver driver = new FirefoxDriver(); command in order to invoke a browser in Selenium, this may be a surprise.

In Sauce Labs, we call the RemoteWebDriver class to connect a remote driver pointed at ondemand.saucelabs.com specifying your Sauce Labs account credentials and desired browser configuration.

Here’s an example of how the Selenium Java test would look like when integrated with Sauce Labs:

As you may see, integrating SauceLabs into your current testing process is pretty straightforward. Sauce Labs is simply used as a remote driver for Selenium, which does not have much impact on the way you currently automate your tests.

Now to seriously simplify that test execution

While using Sauce Labs simplifies the test execution, it still requires developers and testers to set up some things manually, such as adding your authentication credentials, specifying the path to the Sauce Labs cloud, configuring the desired capabilities for your test, enabling reporting to your Sauce Labs dashboard, etc. This can be a hassle if you need to execute multiple endpoints in a short timeframe.

Ranorex Webtestit reduces these repetitive actions and speeds up the remote test execution thanks to the integration with Sauce Labs. Ranorex Webtestit allows the users to set the endpoint configuration by choosing from local endpoints, custom endpoints like BrowserStack, or remote endpoints such as Selenium Grid and Sauce Labs.

Pointing to the Sauce Labs cloud infrastructure will invoke the browser remotely, however, the remaining execution and result workflows remain the same. You’ll continue to manage the test execution from within Ranorex Webtestit.

To add Sauce Labs as a remote endpoint in Ranorex Webtestit, first, choose the ‘Remote endpoint’ tab. Sauce Labs is selected by default.

To use your credentials, fill out the Username and AccessKey fields associated with your Sauce Labs account. Click on the ‘Fetch available capabilities’ button. Then, select your preferred capabilities, including operating system, browser, and browser version. Finally, click the ‘Save endpoint’ button and you’re good to go.

Your Sauce Labs credentials (username and access key) will be inserted in the test code automatically, allowing you to remotely execute your tests from Ranorex Webtestit in an instant.

After this, simply run your test cases in Ranorex Webtestit. Simultaneously, your tests will run in your Sauce Labs dashboard.

When the test is over, you’ll be able to view a regular report in Ranorex Webtestit.

You will also be able to view a Sauce Labs report that will provide a video showing all the actions performed in the test, as well as other important details, including commands, view logs, and metadata.

Conclusion

Using a third-party cloud provider such as Sauce Labs is probably the most convenient way to coordinate your tests across multiple browser, operating system, and device combinations, and ensure better test coverage and maintenance. With Ranorex Webtestit you can speed up this process, even more, thanks to seamless integration with Sauce Labs cloud.

You can download Ranorex Webtestit free 30-day trial here and see for yourself how well it works with Sauce Labs