Automated Testing with Sauce Labs

Sauce Labs is an online provider of cross-platform testing. It offers Selenium testing, mobile testing, and JS unit testing on over 500 OS/browser platforms.

This article will focus on cross-platform testing a web application.

Regardless of whether it’s close to a release or during each development iteration, it’s good practice to assess how your application behaves on different platforms. For a web application, this means testing it on a wide variety of OS/browser version as possible. For example, let’s say you want to support your website on Internet Explorer 11, Safari 8, and Google Chrome and Firefox versions.

This means having the following platform matrix and needing four separate machines:

BrowserWindows 7Windows 8Mac OS X 10.10Linux
Internet Explorer 11XX
Safari 8XX
Google ChromeXXXX

Of course, users all over the world utilize older browser versions as well, and setting up a local infrastructure to support every OS/browser combination would be very cost inefficient.

In this case, we can opt for a Sauce Labs account. They have over 500 OS/browser platforms from which you can choose.

Embedding a Sauce Labs connection into your project

The first thing you need is a Sauce Labs account. Go to and sign in for a free trial. Then login to your account. For a tutorial on how to test manually on Sauce Labs, you can read more here:

Now we’ll look into how we can connect to Sauce Labs and execute a test from an automation framework. The following code samples are written in Ruby with Capybara.

We use environment variables set from the execution command to specify if we want to run the test locally or on Sauce Labs.

if ENV['REMOTE'].to_s =~ /sauce/i

All of the code that follows will sit inside of this branch.

First of all, we need to define the URL that our project will use to communicate with Sauce Labs:

sauce_endpoint = "http://#{TestConstants.sauce_username}:#{TestConstants.sauce_access_key}"

The username is the one you defined when setting up your account, and the access key is listed in your account management panel.

Next, we will define some browsers that we want to have available for executing the test. In Selenium terms, these are called capabilities. Using environment variables, we prepare some capabilities that look like this:

if ENV['BROWSER'] == "ie"
   caps = {
       :platform => "Windows 8",
       :browserName => "Internet explorer",
       :version => "11.0"
 caps = {
     :platform => "Windows 7",
     :browserName => "Chrome",
     :version => "39.0"

Now all we need to do is pass the Sauce Labs URL and the capabilities to Capybara, so they can be used when instantiating a new Selenium test.

Capybara.register_driver :selenium do |app|, :browser => :remote, :url => sauce_endpoint, :desired_capabilities => caps)

Lastly, we use the following command in the command prompt to execute the test on Sauce Labs:

cucumber REMOTE=sauce BROWSER=ie

That should be all you need to know to set up a Sauce Labs account and get started with your cross-platform testing. If you have question or comments, please feel free to leave them in the comments section below!


Ciprian Balea

Ciprian Balea

QA Lead

Ciprian Balea is a QA Lead who works in 3Pillar’s Timisoara, Romania office. Ciprian began his career in software testing 2 years before he graduated from college. He is proficient with Agile practices and is a Certified Scrum Master. He is most interested in the fields of Continuous Integration & Deployment, and Automation and Performance enhancements. Away from work, Ciprian likes outdoors sports and photography.

Leave a Reply

Related Posts

Designing the Future & the Future of Work – The I... Martin Wezowski, Chief Designer and Futurist at SAP, shares his thoughts on designing the future and the future of work on this episode of The Innovat...
The 4 Characteristics of a Healthy Digital Product Team Several weeks ago, I found myself engaged in two separate, yet eerily similar, conversations with CEOs struggling to gain the confidence they needed t...
Recapping Fortune Brainstorm Tech – The Innovation Eng... On this episode of The Innovation Engine, David DeWolf and Jonathan Rivers join us to share an overview of all the news that was fit to print at this ...
4 Reasons Everyone is Wrong About Blockchain: Your Guide to ... You know a technology has officially jumped the shark when iced tea companies decide they want in on the action. In case you missed that one, Long Isl...
The Connection Between Innovation & Story On this episode of The Innovation Engine, we'll be looking at the connection between story and innovation. Among the topics we'll cover are why story ...