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
FirefoxXXXX

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 https://saucelabs.com/ 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: http://www.3pillarglobal.com/insights/sauce-labs-platform-cross-browser-testing-cloud

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}@ondemand.saucelabs.com:80/wd/hub"

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"
   }
else
 caps = {
     :platform => "Windows 7",
     :browserName => "Chrome",
     :version => "39.0"
 }
end

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|
 Capybara::Selenium::Driver.new(app, :browser => :remote, :url => sauce_endpoint, :desired_capabilities => caps)
end

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

Costovation – Giving Your Customers Exactly What They ... On this episode of The Innovation Engine podcast, we delve into “cost-ovation,” or innovation that gives your customers exactly what they want – and n...
AI & Machine Learning Will See You Now, and Other Takea... A 3Pillar team and I spent a few days in Santa Clara recently for the 12th annual Health 2.0 Conference. As usual, we spent some time after the confer...
DevSecOps – The Latest Trends in Application Security ... I spent a very rewarding couple of days at DevSecCon in Boston recently. The conference focused on DevSecOps, which is a catch-all phrase for addressi...
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...
Selecting The Minimum Viable Toolset for Product Managers Recently I was attending a machine learning conference and during a break, found myself deep in conversation with fellow product managers. As is typic...