Parrallel testing with python, cucumber, and docker compose

06.10.2023 | by Ralph Van Der Horst

Parrallel testing with Python, Cucumber, and Docker Compose

Setting Up Parallel Testing with Python, Cucumber, and Docker Compose

In this guide, we will walk you through the steps to set up parallel testing for your Python-based test suite using Cucumber as the test framework and Docker Compose for managing a Selenium Grid. Parallel testing allows you to distribute and run tests concurrently, improving test execution speed.

Prerequisites

  • Python installed on your system.
  • Docker and Docker Compose installed.
Pytest Selenium

Steps

1. Set Up Selenium Grid with Docker Compose

Create a docker-compose.yml file to define your Selenium Grid configuration with multiple nodes (e.g., Chrome, Firefox). Here’s a sample docker-compose.yml:

version: '3'
services:
  chrome:
    image: selenium/node-chrome:4.13.0-20231004
    # Configuration for Chrome node

  firefox:
    image: selenium/node-firefox:4.13.0-20231004
    # Configuration for Firefox node

  selenium-hub:
    image: selenium/hub:4.13.0-20231004
    # Configuration for Selenium Hub
Copy code
docker-compose up -d

2. Install Required Libraries

Install the necessary Python libraries for your project using pip. For example, you may need pytest, pytest-bdd, and selenium.

3. Write Parallel Test Scenarios

Write your test scenarios using Cucumber and pytest-bdd. Organize your tests into separate feature files or scenarios that you want to run in parallel.

4. Configure Parallel Test Execution

For pytest with pytest-xdist: Install the pytest-xdist plugin using pip:

5. Create a pytest configuration file (e.g., pytest.ini) with the following content to specify parallelization options:

[pytest]
addopts = -n auto

6. Execute Parrallel tests

See gitlab project

https://gitlab.com/learnautomatedtesting/paralleltestingpythonseleniumdocker/-/tree/withoutAllure

www.linkedin.com/comm/mynetwork/discovery-see-all?usecase=PEOPLE_FOLLOWS&followMember=ralphvanderhorst

by Ralph Van Der Horst

arrow right
back to blog

share this article

Relevant articles

Mastering Waits in UI Automation

06.10.2023

Mastering Waits in UI Automation

Parrallel testing with Python, Cucumber, and Docker Compose

06.10.2023

Parrallel testing with Python, Cucumber, and Docker Compose

Medior: Use 2fa and UI testautomation

09.09.2023

Medior: Use 2fa and UI testautomation