Selenium Grid
Pre-Requisite
Please make sure that you have installed docker.
Start a docker container with chrome
Use either Selenium Grid 3 or Selenium Grid 4
Using Selenium Grid 3
- Setup Hub
$ docker run -d -p 4444:4444 --name selenium-hub selenium/hub
- Setup Chrome node and register with the hub
$ docker run -d --link selenium-hub:hub selenium/node-chrome
Using Selenium Grid 4
- Setup Hub
$ docker run -d -p 4444:4444 -p 7900:7900 --shm-size="2g" selenium/standalone-chrome:4.0.0-rc-2-prerelease-20210923
Note: Refer here for more info on docker-selenium setup
Setup Docker in IntelliJ Idea
Follow the same steps as shown here to set up docker in IntelliJ.
Once docker is up and running, open http://localhost:4444/grid/console
and check if Selenium Grid 3 with chrome image is up.
Or open http://localhost:4444/
and check if Selenium Grid 4 is up.
Optional Step: If you are using Selenium Grid 4, Open http://localhost:7900/
to inspect container activity with the browser.
Now connect to noVNC client. Click on connect button and enter the password as secret
. You can see the Selenium Grid logo as shown in the below screenshot
Let us execute tests against Selenium Grid containers
Let’s follow the same steps as we did for Selenoid
- Create a webfeed specific to Selenium Grid
- Create a cloud-config file specific to Selenium Grid
- Create a config to use step 1 and 2
Create a webfeed specific to Selenium Grid
Let us create a webfeed file
src/test/resources/cloud_config/seleniumGrid/seleniumGrid-webfeed.json
content as below:
{
"desiredCapabilities": {
"pageLoadStrategy": "eager",
"enableVNC": true
},
"arguments": [
],
"preferences": {
"managed_default_content_settings.cookies": 2
},
"extensions": [
],
"experimentalOptions": {
}
}
Create a cloud-config file specific to Selenium Grid (Hub)
Selenium Grid 3
content as below:
{
"url": "http://localhost:4444/wd/hub"
}
Selenium Grid 4
content as below:
{
"url": "http://localhost:4444"
}
Create a config to the files we created
Let us create seleniumGrid.local.properties
under config.properties
Lets execute our tests !!
./gradlew clean runWebTests -Dconfig=seleniumGrid.local
Selenium Grid 3 Execution
Selenium Grid 4 Execution