CrossBrowserTesting.com

A Design, Development, Testing Blog

  • Product Overview
  • Pricing
  • Back Home
  • Free Trial
  • Design
  • Development
  • Manual Testing
  • Test Automation
  • Visual Testing

Selenium 101: Running Your Test Against Two Browsers at Once

February 6, 2018 By Alex McPeak Leave a Comment

how to run a test on multiple browsers in parallel

how to run a test on multiple browsers in parallel

If you are familiar with automated testing but haven’t yet explored the possibilities of parallel testing, we can tell you right now that you’ve been missing out. Rather than testing sequentially, or running each browser test one after the other, parallel testing allows you to run cross-browser tests simultaneously.

This means if you’re running a test in just two browsers at once, you’re already doubling your speed and productivity. When time is a factor to every software development team, parallel testing is a no-brainer. Selenium is able to run tests in parallel, but CrossBrowserTesting makes it even simpler – allowing you to test across multiple browsers and mobile devices with just a few extra lines of code.

Our example below will be using the Selenium’s Python library, and we’ll run our test against two browsers at once in CrossBrowserTesting with Selenium testing.

First, you want to choose the two browsers you’ll be running the test on. There are a few ways to choose which configuration to test, but the best way to do it for this purpose is to choose the two most common browser versions and operating systems your customers use to visit your web application with Google Analytics.

For this example, we’ll use IE 10 and Chrome 50 on Windows operating systems. Our capabilities will look something like this:

browsers = [
   {“platform”: “Windows 7 64-bit”, “browserName”: “Internet Explorer”,”version”: “10”, “name”: “Python Parallel”}, {“platform”: “Windows 8.1”, “browserName”: “Chrome”, “version”: “50”, “name”: “Python Parallel”},
]

Next, we’ll actually create the test itself, printing out relevant information like browserName to make our debugging experience easier. Our test will simply open CrossBrowserTesting.com and just wait for 3 seconds.

browsers_waiting = [ ]

def get_browser_and_wait(browser_data):
   print ("starting %s\n" % browser_data["browserName"])
   browser = get_browser(browser_data)
   browser.get("http://crossbrowsertesting.com")
   browsers_waiting.append({"data": browser_data, "driver": browser})
   print ("%s ready" % browser_data["browserName"])
   while len(browsers_waiting) < len(browsers):
     print ("working on %s.... please wait" % browser_data["browserName"])
browser.get("http://crossbrowsertesting.com")
     time.sleep(3)

For parallel testing, we’re going to use something called thread dependency, which you’ll see below. Multithreading is the implementation of parallel execution that communicates multiple processes on the CPU.

threads = []
for i, browser in enumerate(browsers):
   thread = Thread(target=get_browser_and_wait, args=[browser])
   threads.append(thread)
   thread.start()

for thread in threads:
   thread.join()

print ("all browsers ready")
for i, b in enumerate(browsers_waiting):
   print ("browser %s's title: %s" % (b["data"]["name"], b["driver"].title))
   b["driver"].quit()

Parallel testing becomes really handy when trying to increase the speed of your testing or actual testing coverage without sacrificing quality. Running a test against two browsers is a really great place to start with this script and already allows you to test twice as fast as doing the same testing sequentially on different browsers.

Once you begin using this method of testing on multiple browsers to extend the reach of longer test cases, the value will be evident. A test suite that previously ran for 5 hours can now be affordably decreased to around 15 minutes, giving your development and testing teams quicker feedback. You can also take your testing suite and boost your coverage immediately, running it against the browsers and devices your customers are actually using. If you extend this over day, weeks, and months, you’ll be benefiting from hours on top of hours of productivity.

For more of our Selenium 101 Series, take a look at the following:

  • Selenium 101: How to Automate Your Login Process
  • Selenium 101: Navigating Waits and Sleeps
  • Selenium 101: How to Take Screenshots During Automated Tests
  • Selenium 101: Automating User Actions
  • Selenium 101: Generating Test Reports
  • Selenium 101: Mastering Selenium Design Patterns
  • Selenium 101: Managing Multiple Tabs

To see more examples in other languages:

  • Python and Selenium
  • Java and Selenium
  • JavaScript and Selenium
  • PHP and Selenium
  • Ruby and Selenium
  • C# and Selenium

Filed Under: how-to, Selenium Tagged With: multiple browsers, parallel testing, Selenium, test automation

Try CrossBrowserTesting

Everything you need for testing on the web. Browsers & Devices included.


  • Grid In The Cloud
  • Simple CI Integrations
  • Native Debugging Tools
  • Real iOS and Android
  • 2050+ Browser/OS Combinations
  • Intuitive REST API

Start Testing Today

Want Testing Tips?

Want the latest tips & strategies from industry experts right to your inbox? Sign up below.
 

Join Over 600,000 Testers & Developers And Start Testing Today

Learn more Free Trial

Features

  • Live Testing
  • Selenium Automation
  • Automated Screenshots
  • Screenshot Comparison
  • Local Testing
  • Real Devices

Solutions

  • Automated Testing
  • Visual Testing
  • Manual Testing
  • Enterprise
  • Internet Explorer

Resources

  • Browsers & Devices
  • Blog
  • Webinars
  • Integrations
  • ROI Calculator

Company

  • About Us
  • Careers
  • Plans
  • Terms of use
  • Security

Support

  • Help Center
  • API Docs
  • Schedule A Demo
  • Contact Us
  • Write For Us