An illustration of cross-browser testing with Selenium.
April 20, 2020

Cross-Browser Testing With Selenium: Web Testing Tutorial

Automation

Many teams use cross-browser testing with Selenium to test on multiple browsers at once for their responsive or traditional websites. Here, we cover what it is and how to do it.

What Is Cross-Browser Testing With Selenium?

Cross-browser testing with Selenium is a technique to test web applications across different browsers in parallel. Selenium supports multiple browser testing.

Selenium releases frequently, and it is always improving. You can also integrate Selenium with other tools as part of your cross-browser testing effort.

How Does Multiple Browser Testing With Selenium Work?

You can use Selenium to do multiple browser testing, including testing Chrome, Safari, Edge, and Firefox browsers. Selenium frameworks provides a built-in grid capability. This enables parallel testing and testing across browsers through various webdrivers and language bindings support.

Testing across multiple browser permutations as well as mobile devices is quite difficult. It requires a lab configuration that is always up to date. That’s why testing web apps across platforms involves leveraging Selenium to automate the effort.

You can do this using tools, such as Perfecto, to execute test cases on different browsers and mobile devices at the same time.

How to Perform Cross-Browser Testing Using Selenium WebDriver, Java, and Perfecto

Here’s a walkthrough of how to perform cross-browser testing in Selenium with Perfecto.

A standard Selenium project requires a local grid configuration. But when you’re working with Selenium and Perfecto, there’s a minimal setup that needs to be done.

You can also watch the video below to see how it works. Or keep reading for a quick introduction.

Watch a demonstration of cross-browser testing with Selenium.

 

1. Configure Your Selenium Project in the IDE

First, you’ll need to configure your Selenium project in the IDE. Let’s assume your Selenium project is already written in Java, JavaScript, or another language binding.

You’ll need to ensure the following are configured.

All of the POM.XML maven file dependencies are in place:

  • Perfecto reporting SDK dependencies
  • Selenium SDK dependencies
  • testNG dependencies
  • Maven plugin dependencies

 

<!-- Reportium SDK -->
<dependency>
   <groupId>com.perfecto.reporting-sdk</groupId>
   <artifactId>reportium-java</artifactId>
   <version>${reportium-sdk.version}</version>
</dependency>
<dependency>
   <groupId>com.perfecto.reporting-sdk</groupId>
   <artifactId>reportium-import-java</artifactId>
   <version>${reportium-sdk.version}</version>
</dependency>
<dependency>
   <groupId>com.perfecto.reporting-sdk</groupId>
   <artifactId>reportium-import-selenium</artifactId>
   <version>${reportium-sdk.version}</version>
</dependency>
<dependency>
   <groupId>com.perfecto.reporting-sdk</groupId>
   <artifactId>reportium-allure-integration</artifactId>
   <version>1.1.9</version>
</dependency>
<dependency>
   <groupId>com.perfecto.reporting-sdk</groupId>
   <artifactId>reportium-testng</artifactId>
   <version>${reportium-sdk.version}</version>
</dependency>

 

Perfecto unique user configuration:

  • Perfecto cloud URL
  • Perfecto security token
  • Perfecto username

And you’ll also need the target platform under test configured in a testNG.xml file. This file specifies on which desktop browsers and mobile devices to execute the tests.

 

case "Firefox 64":
    device = false;
    fast = true;
    capabilities.setCapability("platformName", "Windows");
    capabilities.setCapability("platformVersion", "7");
    capabilities.setCapability("browserName", "Firefox");
    capabilities.setCapability("browserVersion", "64");
    capabilities.setCapability("resolution", "1280x1024");
    capabilities.setCapability("location", "US East");
    break;

 

2. Set Up Perfecto With Selenium Execution

To get started, you’ll need to have Perfecto set up that you’ll need for cross-browser testing with Selenium execution.

You’ve configured the Selenium project in the IntelliJ IDEA environment and built the testNG file. Now, the only thing that a user needs to do is to execute the testNG.XML file.

Selenium developers can use testNG to also pass many of the above-mentioned configurations as parameters (including cloud URL, Selenium address, username are examples). This creates much cleaner test code.

3. Run the Test Across Browsers

After triggering the execution from the IDE, you can login to the cloud to see the execution happening within the Perfecto live stream. In this view, you can track the execution progress. You can also zoom into a specific platform that is running.

In our execution, we tested the Boston Globe responsive website across 14 different web and mobile configurations in the Perfecto cloud.

In the demo video, you’ll see the devices and device capabilities are defined. So are the characteristics of the device for that test.

Once the testing is done, Perfecto will release the browser and mobile devices. Perfecto then can do a quick clean-up — and generate the subsequent report for you.

This image shows cross-browser testing with Selenium and Perfecto.

4. Define Reporting Capabilities

Next, you can review each single test report from the 14 that were produced. Each report gives you a video recording, screenshots, network HAR files, logs, and cross-platform visual comparison abilities.

 

An example of multiple reports in Perfecto.
Compare reports from cross-browser testing with Selenium and Perfecto.

 

Example

In our example, we’ve entered a couple of variables for a website — homepage, zip code, and more. The Selenium test will run on the site — and the reporting capabilities will capture what happens.

5. Analyze Test Results

Finally, you may have encountered a failure that is not a real defect. The failure reason tab within the reporting is the first step for analyzing the root cause — and deciding how to move forward.

There could either be a test coding issue, a platform specific configuration issue, or an environment issue. The initial analysis helps you improve the stability of your Selenium scripts and keep a healthy testing pipeline.

This is just the beginning of what you can do for cross-browser testing using Selenium WebDriver, Java, and Perfecto. Watch the full demo video above to go into more advanced Selenium test automation.  

Automate Cross-Browser Testing using Selenium With Perfecto

The best way to do cross-browser testing is of course through test automation with Selenium. To ensure scalability, reliability and advanced reporting and productivity, it’s recommended to move the execution to the cloud. And the best way to automate cross-browser testing with Selenium in the cloud, is to use Perfecto.

Perfecto and Selenium are seamlessly integrated. That means you can:

  • Connect your Selenium code to the Perfecto cloud.
  • (Easily) create a Selenium Grid with Perfecto in the cloud with browsers and mobile devices.
  • Test using Selenium WebDriver and Java — or other languages.

By automating cross-browser testing using Selenium with Perfecto, you’ll maximize test coverage. You’ll get fast execution of tests across multiple browsers and devices. And you’ll get advanced reporting so you can accelerate feedback loops, debug, and ensure higher quality.

Ready to get started on cross-browser testing using Selenium and Perfecto? You can get started for free with a 14-day trial.

Try Perfecto With Selenium

 

Related Content