Exercise : 2 Local selenium grid using Docker - Raneesh02/ref_workshop_2 GitHub Wiki
Local selenium grid using Docker
Prerequisite :
Docker needs to be installed and working
Install docker https://www.docker.com/products/docker-desktop/
For virtualisation issues : https://support.hp.com/in-en/document/ish_5637142-5637191-16
Step 1 : Launch a standalone selenium grid
What is selenium grid ? https://toolsqa.com/selenium-webdriver/selenium-grid/
Run a standalone selenium grid :
Windows:
docker run -d -p 4444:4444 -p 5900:5900 -p 7900:7900 --shm-size="2g" selenium/standalone-chrome:latest
Mac :
docker run -d -p 4444:4444 -p 5900:5900 -p 7900:7900 --shm-size 2g seleniarm/standalone-chromium:latest
Notice the name seleniarm and chromium , this is specific to mac
Explanation of the command :
-
docker run: This command is used to create and start a new Docker container.
-
-d: Runs the container in detached mode. Detached mode allows the container to run in the background.
-
-p 4444:4444: Maps port 4444 on the host machine to port 4444 in the container. Port 4444 is typically used by Selenium Grid to expose the WebDriver API.
-
-p 5900:5900: Maps port 5900 on the host to port 5900 in the container. This port is used for VNC (Virtual Network Computing) access. VNC allows you to view and interact with the Chromium browser session running inside the container remotely.
-
-p 7900:7900: Maps port 7900 on the host to port 7900 in the container. This port is used to expose a noVNC web interface. noVNC allows you to interact with the Chromium browser inside the container via a web browser, similar to VNC but accessible over HTTP.
-
--shm-size 2g: Sets the size of the /dev/shm (shared memory) to 2g (2 gigabytes). Shared memory is used by browsers for certain types of operations like rendering pages. Increasing the shared memory size can help prevent browser crashes due to low shared memory.
-
selenium/standalone-chrome:latest: Specifies the Docker image to use. This image is an ARM-based version of Selenium Standalone with Chromium. The :latest tag indicates that the latest version of this image should be pulled from the Docker registry.
Step 2 : open HTTP://localhost:4444 in any browser
you will see selenium grid up and running with one session of chrome running
Step 3: Change grid URL value to change to use remote web driver
Go to src/main/resources/configuration.properties and write localhost for gridurl value
selenium.gridurl=localhost
Go to src/main/java/Base/DriverManager.java and comment headless execution line (we want to see execution now)
chromeOptions.addArguments("--headless");
Do the execution via command mvn test
and view the execution on http://localhost:4444/ui/#/sessions