Despite Google Chrome’s market dominance, non-Chrome browsers account for more than one-third of global online usage. Considering the complexity of maintaining thirty years of online standards, it’s not unexpected that the same web application behaves differently across browsers. As a result, developers who want to provide a uniform, functional experience for all consumers must prioritize cross-browser testing.
Testing across browsers poses unique issues. For example, Google Chrome can function on almost every operating system, but Safari is solely compatible with Apple platforms such as macOS, iPadOS, and iOS.
This post will explain cross-browser testing in Selenium, Selenium Grid, and how to set it up.
What is Cross Browser Testing in Selenium?
Cross-browser testing is the process of testing a website on several browsers, such as Internet Explorer, Chrome, and Firefox, to ensure that it works properly in each of them. Cross-browser compatibility refers to the ability of a website or online application to work across many browsers and operating systems.
However, manually testing a website across numerous browsers is extremely time-consuming and tedious. Consider the circumstance in which 100 test cases must be executed manually. Imagine running the same tests on five different browsers. The time and effort it takes increases dramatically. However, if the same tests are automated with Selenium, they may be run concurrently and in significantly less time. Cross-browser testing in Selenium will also prevent any issues caused by manual mistakes.
What is Selenium?
Selenium suite consists of four components:
- Selenium Grid
- Selenium IDE
- Selenium RC
- Selenium Webdriver
What is a Selenium Grid?
Selenium Grid is a testing tool (part of the Selenium Suite) built on a ‘client-server’ architecture. In Selenium Grid nomenclature, the client computer is referred to as the ‘Hub’, and the server(s) as the ‘Nodes’.
Selenium-grid for cross-browser testing configuration enables you to perform cross-browser testing on a multitude of desktop computers using different browsers (as well as browser versions) and operating systems. As a result, it provides the necessary level of ‘parallelism’ and ‘distribution’ in your test execution environment.
A Selenium Grid configuration can only have one Hub and ‘n’ number of nodes. The primary function of the ‘hub machine’ is to disseminate the test case given to the ‘node machine’ that has the capabilities/requirements needed to execute the test case for cross-browser testing. More on Hub and Node (the basic components for setting up Selenium Grid architecture) will be covered in subsequent parts.
Selenium Grid is available in two versions: 2.0 and 1.0. Selenium Grid 2.0 is the most popular choice among automation testers as it supports Selenium RC (Remote Control) and Selenium WebDriver scripts.
When should testers use Selenium Grid?
Testers are advised to employ selenium-grid for cross-browser testing under the following conditions:
- When running tests across various browsers and versions, diverse devices, and operating systems.
- To lessen the duration required for executing a test suite.
Selenium Grid enhances the efficiency of test result processing. This is particularly beneficial for extensive test suites with extended runtime. It provides flexibility and guarantees optimal test coverage within a constrained time frame. With the utilization of virtual infrastructure, maintenance tasks are simplified.
Setting up Selenium Grid for cross-browser testing
In order to conduct cross-browser testing using Selenium Grid, it’s necessary to establish a development environment comprising both hub and nodes.
Download and install the Selenium Server
As the Selenium server is distributed as a JAR file, ensure that Java is installed and properly configured in the system PATH. You can obtain the latest version of the Selenium Server from the official website. Since there have been numerous version releases recently, it’s important to carefully note the version you’re using while following this guide.
Starting Selenium Server
Once you have downloaded the standalone file, navigate to the directory containing the JAR file in a terminal and execute the following command:
java -jar selenium-server-4.2.0.jar -role hub
NOTE: Replace “4.2.0” with the version you have downloaded.
The provided command will initiate the Selenium Grid Hub as a local host server on port 4444. You can modify this port by utilizing the -host parameter within the command.
Accessing the Grid console
When browsing http://localhost:4444/grid/console, the Grid presents various configuration details of the server on a webpage. You’ll find a link labelled “View config” on this page, which redirects you to another page containing additional information about the current hub’s settings.
Configuring a new node
With the steps completed thus far, you may have only succeeded in getting one node operational. To add additional nodes, we must register new ports. Thus, enter the following command in the terminal:
java -jar selenium-server-4.2.0.jar -role node -hub http://localhost:4444/grid/register -port 5555
By default, the Grid permits up to five instances of Chrome, five instances of Firefox, and one instance of Internet Explorer. To modify these settings, include the following command parameter: -browser “browserName=browser name>,version=browser version>,maxInstances=maximum instances of the browser>,platform=platform name>”.
For instance, on a Windows operating system, the following command can be utilized to permit only one instance of Firefox:
java -jar selenium-server-4.2.0.jar -role node -hub http://localhost:4444/grid/register -port 5555 -browser “browserName=firefox,maxinstance=1,platform=WINDOWS”
Upon navigating to https://localhost:5555/grid/console, you’ll notice that only a single instance of Firefox is displayed.
The Grid hub and node machines are now configured and prepared for utilization. To execute test scripts on node machines, you can utilize an IDE such as Eclipse or IntelliJ to create WebDriver code.
Selenium test scripts follow a unique pattern distinct from other test framework scripts, and the creators have furnished guidelines outlining the construction of a functional and successful Selenium test script.
We’ve comprehensively covered cross-browser testing utilizing Selenium Grid. Now, you can effortlessly test your websites across all available browsers and their versions, ensuring a consistent user experience for all users, regardless of their chosen browser, through the aid of cross-browser testing.