DEV Community

Cover image for Creating a Selenium grid with Docker Compose and run python tests.
DelRayo
DelRayo

Posted on

Creating a Selenium grid with Docker Compose and run python tests.

We are going to use docker compose for creating a Selenium grid and run some basic python tests against the grid.

Image description

As always the files can be found on GitHub .

  1. Download the repo,
  2. Open a terminal in the repo folder
  3. Execute "docker-compose up -d".

Image description

That will spin up the grid, when docker finish preparing your grid you should go to http://localhost:4444/grid/console just to verify that everything is ok.

Image description

And then just run a simple test against this grid.
For doing this you should create a new selenium driver pointing to the grid, if you are using python is something like this for chrome :

driver = webdriver.Remote(
   command_executor="http://127.0.0.1:4444/wd/hub",
   desired_capabilities={
            "browserName": "chrome",
        })

driver1 = webdriver.Remote(
   command_executor="http://127.0.0.1:4444/wd/hub",
   desired_capabilities={
            "browserName": "chrome",
        })

driver2 = webdriver.Remote(
   command_executor="http://127.0.0.1:4444/wd/hub",
   desired_capabilities={
            "browserName": "chrome",
        })
Enter fullscreen mode Exit fullscreen mode

You can find a test example file in https://github.com/delrayo/DockerComposeSeleniumGrid/blob/main/test.py

Hope this helps you on your testing.

Latest comments (0)