Getting Started with Selenium - Chapter 7: How To Scale Your Tests

Sauce AI for Test Authoring: Move from design to execution in minutes.|xBack to ResourcesBlogPosted

January 18, 2026 · 7 min read · Tool Comparison

Sauce AI for Test Authoring: Move from design to execution in minutes.

|

x

Back to Resources

Blog

Posted March 19, 2014

Getting Started with Selenium - Chapter 7: How To Scale Your Tests

quote

This post is the seventh in a series of “ Getting Started with Selenium Testing ” posts from Dave Haeffner, a renowned expert on Selenium and automate testing, and a frequent contributor to the Sauce blog and Selenium community. This series is for those who are brand new to test mechanisation with Selenium and a new chapter will be post every Tuesday (eight chapters in all).

How To Scale Your Tests

If you & # x27; ve always need to test lineament in an older browser like Internet Explorer 8 then odds are you ran a practical machine (VM) on your estimator with a & quot; legit & quot; version of Windows XP. Handy, but what happens when you want to check thing on multiple adaptation of IE? Now you & # x27; re looking at multiple VMs. And what about when you need to scale and cover other browser and Operating System (OS) combination? Now you & # x27; re looking at provisioning, escape, and maintaining your own farm of machines and stand up something like Selenium Grid to coordinate tests across them. And all you wanted to do was run your tryout on the browsers you cared about ... Rather than direct on the overhead of a test infrastructure you can easily outsource thing to a third-party cloud supplier - like Sauce Labs

A Selenium Remote, Selenium Grid, And Sauce Labs Primer

At the bosom of Selenium at scale is the use of Selenium Grid and Selenium Remote. Selenium Grid lets you distribute test execution across respective machine and you connect to it with Selenium Remote - specifying the browser type and version through the use of Selenium Remote & # x27; sCapabilities. This is fundamentally how Sauce Labs works. Behind the curtain they are ultimately running Selenium Grid, and they receive and action your tests through Selenium Remote - knowing which browser and operating system to use because of theCapabilitiesits users specify. Let & # x27; s dig in with an exemplar.

An Example

Part 1: Initial Setup

NOTE: You & # x27; ll require an account to use Sauce Labs. Theiroffers plenty to get you start.With Sauce Labs we ask to provide specifics about what we need in our test environment, our certification, and configure Selenium a little bit differently than we have been. Building onthe last write-up, let & # x27; s kickoff by creating a new config file for cloud execution (& # x27; config_cloud.rb & # x27;).filename: config_cloud.rb

1
ENV[& # x27; base_url & # x27;]||=& # x27; http: //the-internet.herokuapp.com & # x27;
2
ENV[& # x27; host & # x27;]=& # x27; saucelabs & # x27;
3
ENV[& # x27; operating_system & # x27;]||=& # x27; Windows XP & # x27;
4
ENV[& # x27; browser & # x27;]||=& # x27; internet_explorer & # x27;
5
ENV[& # x27; browser_version & # x27;]||=& # x27; 8 & # x27;
6
ENV[& # x27; SAUCE_USERNAME & # x27;]||=& # x27; your-sauce-username & # x27;
7
ENV[& # x27; SAUCE_ACCESS_KEY & # x27;]||=& # x27; your-sauce-access-key & # x27;
8
Notice the use ofa host surround variable.Thisis what we& # x27; ll use in our spec_helper file to determine whether to run things topically or in the cloud -- and we & # x27;ll use the other environment variable to live theCapabilities.filename: spec/spec_helper.rb
9
require & # x27; selenium-webdriver & # x27;
10
11
RSpec.configuredo|config|
12
13
config.before(:each)do
14
caseENV[& # x27; host & # x27;]
15
when & # x27; saucelabs & # x27;
16
caps =Selenium::WebDriver::Remote::Capabilities.send(ENV[& # x27; browser & # x27;])
17
caps.version=ENV[& # x27; browser_version & # x27;]
18
caps.platform=ENV[& # x27; operating_system & # x27;]
19
caps[:name]= example.metadata[:full_description]
20
21
@driver =Selenium::WebDriver.for(
22
:remote,
23
url:& quot; http: // # {ENV [& # x27; SAUCE_USERNAME & # x27;]}: # {ENV [& # x27; SAUCE_ACCESS_KEY & # x27;]} @ ondemand.saucelabs.com:80/wd/hub & quot;,
24
desired_capabilities: caps)
25
else
26
@driver =Selenium::WebDriver.for:firefox
27
end
28
end
29
30
config.after(:each)do
31
@driver.quit
32
end
33
34
end
35

Notice that we & # x27; ve added a conditional to assure on the legion environs variable. If the host is set to & # x27; saucelabs & # x27;, so we configure the capabilities for Selenium Remote, passing in the requisite information that we will need for our Sauce Labs session. Otherwise, it will run our tests locally using Firefox. Now if we run our tryout entourage (rspec -r ./config_cloud.rb) and navigate to our Sauce Labs Account page then we should see each of the test lead in their own job, with proper names, against Internet Explorer 8.

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

Part 2: Test Status

The only thing miss now is the pass/fail status of the job. In our local terminal window everything should be arrive up green. But in the list of our Sauce jobs, the & # x27; Results & # x27; panel for everything will just say & # x27; Finished & # x27;. This will make our results less useful in the long run, so let & # x27; s fix it. Thanks to Sauce Labs & # x27; gem, it & # x27; s really simple to do. After we install it we will need to require it someplace, and our & # x27; config_cloud.rb & # x27; file look like a consistent property, since we will only need it when bunk our tests in Sauce. So let & # x27; s add it to the top of the file.filename: config_cloud.rb

require & # x27; sauce_whisk & # x27; ...

All that & # x27; s leave is to add an activeness to ourafter (: each)cube in our & # x27; spec_helper & # x27; file. Before we issue@ driver.quitwe will want to grab the job ID from our@driverobject and set the job status based on the test result. Also, we & # x27; ll need to make sure that it only fulfil when running examination against Sauce Labs -- so we & # x27; ll require to wrap it in a conditional check against the host environment variable.filename: spec/spec_helper.rb

1
require & # x27; selenium-webdriver & # x27;
2
3
RSpec.configuredo|config|
4
...
5
6
config.after(:each)do
7
ifENV[& # x27; horde & # x27;]==& # x27; saucelabs & # x27;
8
if example.exception.nil?
9
SauceWhisk::Jobs.pass_job @driver.session_id
10
else
11
SauceWhisk::Jobs.fail_job @driver.session_id
12
end
13
end
14
15
@driver.quit
16
end
17
18
end

Now when we run our tests (rspec -r ./config_cloud.rb) and navigate to our Sauce Labs Account page, we should see our tests running like before - but now when they finish there should be a proper test status (e.g., & # x27; Pass & # x27; or & # x27; Fail & # x27;).

Speeding Up Your Tests

Now we can easy run our tests in Sauce Labs, but it & # x27; s a real bummer that all of our trial are fulfill in series. As our suite grows, thing will quickly commence to add up and actually hamper our ability to get feedback quickly. With parallelization we can quickly remedy this -- and there are a few ways to go about achieve it.

  • In code

  • Through a exam moon-curser

  • Through your Continuous Integration (CI) Server

Outro

For a deeper dive on how to scale your tests (e.g., running tests in parallel, testing coating behind a firewall, output Sauce Labs job information into your exam results, etc.) so be sure to insure out The Selenium Guidebook. Up next, in my last write-up, I & # x27; ll assist you tie everything together through the use of Uninterrupted Integration.

Dave is the author of Elemental Selenium (a free, once weekly Selenium tip newssheet that is read by hundreds of testing professionals) as good as a new book, The Selenium Guidebook. He is also the creator and sustainer ofChemistryKit(an open-source Selenium framework). He has helped legion companies successfully implement automated acceptance screen; include The Motley Fool, ManTech International, Sittercity, and Animoto. He is a founder and co-organizer of theSelenium Hangoutand has spoken at numerous conferences and meetups about acceptance testing.

Published:
Mar 19, 2014
Topics
Share this post
Copy Share Link
LinkedIn
© 2026 Sauce Labs Inc., all rights reserved. SAUCE and SAUCE LABS are registered earmark have by Sauce Labs Inc. in the United States, EU, and may be registered in other jurisdiction.
robot
quote

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free