End to end tests with Selenium Grid and Python

I’ll show you how to set up a comprehensive testing environment quickly and effortlessly.

We’ll be using Selenium WebDriver within a Selenium Grid, run locally via a Docker Compose configuration, and writing our tests in Python.

For reporting, we’ll use Allure.

And the best part? You can set everything up with just one command.

You’ll need:

First, download the template:

git pull https://github.com/andgineer/e2e-tests.git

Navigate to the e2e-tests folder and run:

docker-compose up -d

Now, a Selenium Grid is operational, supporting Chrome, MS Edge and Firefox browsers for testing, console is available at http://localhost:4040.

It automatically generates reports from the data inside the allure-results folder.

Resulting Allure report is published at http://localhost:4040.

To run tests from tests/ and view the report, execute:

. ./activate.sh
./scripts/test.sh

Our tests include a --host parameter to specify the URL of the web application being tested. Implementation details see in pytest hook pytest_addoption of conftest.py.

For instance, to test https://google.com, you would run:

scripts/test.sh --host=https://google.com

This test will fail, as the word “Python” is not present on the Google main page.

For tips on capturing screenshots when tests fail and adding them to the report, check out my blog post.