Chapter 13. Cross-Browser Testing

In this chapter, we will cover:

  • Setting up Selenium Grid Server for parallel execution
  • Adding nodes to Selenium Grid for cross-browser testing
  • Creating and executing the Selenium script in parallel with TestNG
  • Creating and executing the Selenium script in parallel with Python
  • Using Cloud tools for cross-browser testing
  • Running tests in headless mode with PhantomJS

Introduction

Organizations are adopting virtualization and cloud-based technologies to reduce costs and increase efficiency. Virtualization and cloud-based infrastructure can also be used to scale the test automation by reducing investment in physical hardware needed to set up the test environment. Using these technologies, web applications can be tested on a variety of browser and operating system combinations. Selenium WebDriver has unmatched support for testing applications in virtual environment, executing tests in parallel, reducing costs, and increasing speed and coverage. This chapter will cover recipes to configure and execute Selenium WebDriver tests for parallel or distributed execution.

Running tests in parallel requires two things: an infrastructure to distribute the tests, and a framework that will run these tests in parallel in the given infrastructure. In this chapter, we will first create a distributed infrastructure, and then create some tests that will be executed in this distributed test environment.

Selenium Grid transparently distributes our tests across multiple physical or virtual machines so that we can run them in parallel, cutting down the time required to run tests. This dramatically speeds up testing, giving us quick and accurate feedback.

With Selenium Grid, we can leverage our existing computing infrastructure. It allows us to easily run multiple tests in parallel, on multiple nodes or clients, in a heterogeneous environment where we can have a mixture of OS and browser support. Here is an example of the Selenium Grid architecture with the capabilities to run tests on Linux, Windows, Mac, iOS, and Android platforms:

Introduction

Selenium Grid allows us to run multiple instances of WebDriver or Selenium Remote Control in parallel. It makes all these nodes appear as a single instance, so tests do not have to worry about the actual infrastructure. Selenium Grid cuts down on the time required to run Selenium tests to a fraction of the time that a single instance of Selenium would take to run, and it is very easy to set up and use.

The Selenium Server standalone package includes the Hub, WebDriver, and Selenium RC that are needed to run the Grid.

Testing the framework for parallel execution

In this chapter, we need a testing framework that supports parallel runs of our tests. We will use TestNG (http://testng.org/) to run parallel tests with Selenium WebDriver Java bindings. TestNG has a threading model to support running multiple instances of the same test using an XML-based configuration. TestNG is pretty similar to JUnit.

We will also use a raw method to run tests in parallel for Python bindings using the subprocess module. However, you can also use nose for parallel execution in Python.

To run tests in parallel with .NET bindings, you can use PUnit or MSTEST, and for Ruby, you can use DeepTest.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.182.96