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

3Pillar Recognized as an Experience Designer In Report by In... Fairfax-based product development company named to its second report in 2018FAIRFAX, VA (June 26) - Today, 3Pillar Global, a global custom softwar...
Why You Need Automated Testing to Reach DevOps’ Holy Grail Automated testing is required to reach DevOps’ Holy Grail - continuous deployment. Despite what you may have seen in Indiana Jones and the Last Crusad...
AI, Chatbots & Natural Language Processing: The Present... For this episode of The Innovation Engine podcast, we take a look at what the future of digital healthcare may hold for both patients and providers. W...
Should You A/B Test? First of all, what does A/B testing mean? A/B testing starts when you want to be sure you're making the right decision. Simply put, A/B testing is c...
Change Blindness in UX There is a strong discrepancy between the amount of information being transmitted and the amount of information our brains have the capacity to proces...