Setup Selenium Grid on Docker with Cross Browser Testing

What is Selenium Grid?

It allows the execution of WebDriver scripts on remote machines (virtual or real) by routing commands set by the client to remote browser instances.

When to use Grid?

  • To run your tests against multiple browsers, multiple versions of browser, and browsers running on different operating systems.
  • To reduce the time it takes for the test suite to complete a test pass.

How it works?

One server acts as the hub that routes JSON formatted test commands to one or more registered Grid nodes. Tests contact the hub to obtain access to remote browser instances. The hub has a list of registered servers that it provides access to, and allows control of these instances.

Setup on Docker

Selenium Grid can be setup on docker by creating a separate container for Selenium Hub and each Nodes respectively. Once all containers are up and running then the Node containers should be linked to the Hub container.

Following Docker commands can be used to setup Selenium Grid:

//Pull Selenium-hub image using command 
docker pull selenium/hub

//Pull FireFox Debug image using command
docker pull selenium/node-firefox-debug

//Pull Chrome Debug image using below command
docker pull selenium/node-chrome-debug

//Check all the images are downloaded
docker images

//Running Selenium-hub inside Docker 
docker run -d -p 4446:4444 --name selenium-hub -P selenium/hub

//Browser Configuration
localhost:4446/grid/console

//Check Selenium Hub container has started
docker ps -a

//Linking chrome image to Selenium-hub
docker run -d -P --link selenium-hub:hub selenium/node-chrome-debug

//Linking FireFox image to Selenium-hub
docker run -d -P --link selenium-hub:hub selenium/node-firefox-debug

//Verify Selenium Hub and node are running
docker logs "Selenium-hub ContainerId"

Clone the GitHub repository to start running your Selenium Tests across different browsers and platforms using Selenium Grid.

Setup Vnc Viewer to view your tests running on Docker based Linux platforms.

 

 

Share

Bijan Patel

Founder & Creator of QAScript | 12+ years of IT Experience | Full Stack Automation Engineer | Blogger | Trainer

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!