Executing Selenium Scripts Using Docker ContainerExecuting Selenium Scripts Using Selenium Grid Approach

Executing Selenium Scripts Using Selenium Grid Approach

Selenium Grid is a tool used for distributing Selenium WebDriver tests across multiple machines (nodes) in a network. It allows you to execute tests in parallel on different browsers, operating systems, and versions, all managed centrally by a hub. Using Selenium Grid involves setting up a distributed testing environment for Selenium WebDriver tests.

Executing Selenium Scripts on Windows

Make sure to install Java and Maven to run Selenium scripts. If not, refer to Configuring web applications using Java Selenium framework.

To install Docker Desktop for windows installer, click here (optional step).

Setting the Type and the Hub URL in the Application Settings File

Perform the following:

After generating the script, download it to your local folder.

This folder must contain the script file that you have generated.

Open the folder where you downloaded the script.

For example, if your script is located at AlgoAFScript_202402121131\src\test\java, navigate to this folder. Applications.xml file will be available in the Java folder as shown:

File explorer listing with ApplicationSettings.xml file highlighted among project folders

Open the Application Settings file and locate the setting related to the 'Type' and Hub URL .

Set Type setting to 'Selenium GRID' and Update the Hub URL with the IP address of your system or the IP address of the environment that you are running followed by colon and the port number, as shown:

ApplicationSettings XML file with HubURL and Type Selenium GRID fields highlighted

Adding the Docker files into the algoQA Script Generated Folder

Perform the following:

Download the attached Docker compose YAML file, which sets up a Selenium Grid environment with a Selenium Hub (selenium-hub) and a Chrome node (chrome). The Selenium Hub manages the distribution of Selenium tests across multiple nodes (chrome in this case). The Chrome node is configured to connect to the Selenium Hub using environment variables and to expose its VNC port for visualization.

The VNC port is a networking protocol that enables you to visualize and interact with Chrome browser instances running in the Docker containers. Exposing the VNC port allows direct observation and interaction with the browser during test execution.

By default, VNC servers start at port 5900 and increase sequentially for each additional display. For example, a VNC server assigned to display number 1 operates on port 5901, display number 2 on port 5902, and so forth. This sequential pattern ensures each VNC session is uniquely identified by its corresponding port number.

Navigate to the Downloads folder > open the Docker compose file and save the Docker file into same folder where your script is generated, as shown:

File explorer view of project folder with Dockerfile highlighted among src, target and pom.xml

Executing Scripts

Perform the following:

To start all the services defined in a Docker Compose configuration file, run the following command in the command prompt:

docker-compose up

Run the following command to execute the scripts in the command prompt:

mvn test

Run the following command to stop and remove containers, networks, and volumes created by

docker-compose up
docker-compose down

This command is used to clean up resources after running a Docker Compose application, ensuring that all containers and associated resources are properly shut down and removed.

Attachment

Docker compose file.yml

YML, 604 Bytes