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

High Availability and Automatic Failover in Hadoop Hadoop in Brief Hadoop is one of the most popular sets of big data processing technologies/frameworks in use today. From Adobe and eBay to Facebook a...
How the Right Tech Stack Fuels Innovation – The Innova... On this episode of The Innovation Engine podcast, we take a look at how choosing the right tech stack can fuel innovation in your company. We'll talk ...
The Road to AWS re:Invent 2018 – Weekly Predictions, P... For the last two weeks, I’ve been making predictions of what might be announced at AWS’ upcoming re:Invent conference. In week 1, I made some guesses ...
Building a Microservice Architecture with Spring Boot and Do... This is the fourth blog post in a 4-part series on building a microservice architecture with Spring Boot and Docker. If you would like to read the pre...
Building a Microservice Architecture with Spring Boot and Do... Part III: Building Your First Microservice, its Container, and Linking Containers We're about ready to actually get started with building a microserv...