Skip to content

Schveitzer/selenium-python-distributed-parallelized-tests

Repository files navigation

Selenium distributed and parallelized tests with Python And Selenoid or Selenium Grid

In this project I demonstrate how to use Python with Pytest, Selenium and Selenoid or Selenium Grid for automation E2E tests parallelized or distributed.

The tests code is simple,for that reason I don't use PageObject, abstraction and others design patterns, the objective this project is show a configuration of Pytest and Selenoid for execution tests in distributed an parallelized ways.

I suggest using Selenoid instead of Selenium Grid, the selenium grid is heavy and slow, in addition there are other aspects that make the choice of Selenoid click here to see

This project includes:

  • Frameworks:

    • Pystest
    • Allure
    • Selenium 4
  • Features:

    • Distributed tests over different browsers
    • Parallelized tests
    • Screenshot on fail testes
    • Visualization the execution of tests with Selenoid UI or Selenium Grid 4
    • Record video of tests
    • Pytest fixtures and parametrize
    • Use docker for infrastructure
    • Report with Allure

Demo App

For these tests I use a Sauce Labs demo app which can be found here: Sauce Demo

Requirements

Getting Started

Creat a virtual environment:

$ python -m venv venv
$ source venv/bin/activate

Install dependencies:

$ pip3 install --no-cache-dir -r requirements.txt

Start Selenoid Server:

$ docker-compose up

OR

Start Selenium Grid Server:

$ docker-compose -f docker-compose-selenium-grid.yml up

Selenoid or Selenium grid UI:

After started the Selenoid or Selenium Grid service, it is possible to manage and view the test sessions, just access the address in the browser:

Selenoid: http://localhost:8080/#/

Run Img

Selenium Grid: http://localhost:4444/

Run Img

To run tests in Chrome and Firefox Browser:

$ pytest -vv -q --browser_name="chrome" -q --browser_name="firefox" --alluredir=results/allure_report

To run tests in Chrome Browser:

$ pytest -vv -q --browser_name="chrome" --alluredir=results/allure_report

To run tests in Firefox Browser:

$ pytest -vv -q --browser_name="firefox" --alluredir=results/allure_report

To run tests in local Chrome Browser:

$ pytest -vv -q --browser_name="local" --alluredir=results/allure_report

To run tests in parallel mode:

To run more than one test simultaneously, just add the -n parameter informing the maximum number of tests to be run simultaneously, the maximum possible number is limited by the number of threads that the processor has to run the tests. For example to run 2 tests at the same time in chrome and firefox:

$ pytest -n2 -vv -q --browser_name="chrome" -q --browser_name="firefox" --alluredir=results/allure_report

Enabling video record (Run only in selenoid):

In conftest.py change de value of enableVideo to True, after running the tests, the videos will be stored in the results/video folder:

selenoid_options = {"enableVNC": True,
                        "enableVideo": True,
                        "videoName": f'{request.node.nodeid}.mp4',
                        "videoCodec": "mpeg4",
                        "enableLog": False}

Add more versions or browser in Selenoid:

To add new browsers, just change the browsers.json file, you also need to add the browsers image at the end of the docker-compose.yml file, this page has more information Browsers Configuration File

Reports

You must have the allure client installed

Run the command below to generate the test report:

$ allure generate --clean results/allure_report -o results/allure_result 

To view the report in the browser:

$ allure open results/allure_result

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages