This tutorial will make web UI testing easy. We will build a simple yet robust web UI test solution using Python, pytest, and Selenium WebDriver. We will learn strategies for good test design as well as patterns for good automation code. By the end of the tutorial, you’ll be a web test automation champ! Your Python test project can be the foundation for your own test cases, too.
- Set Your Test Automation Goals (Chapter 1)
- Create A Python Test Automation Project Using Pytest (Chapter 2)
- Installing Selenium WebDriver Using Python and Chrome (Chapter 3)
- Write Your First Web Test Using Selenium WebDriver, Python and Chrome (Chapter 4)
- Develop Page Object Selenium Tests Using Python (Chapter 5)
- How to Read Config Files in Python Selenium Tests (Chapter 6)
- Take Your Python Test Automation To The Next Level (Chapter 7)
- Create Pytest HTML Test Reports (Chapter 7.1)
- You’re here → Parallel Test Execution with Pytest (Chapter 7.2)
- Scale Your Test Automation using Selenium Grid and Remote WebDrivers (Chapter 7.3)
- Test Automation for Mobile Apps using Appium and Python (Chapter 7.4)
- Create Behavior-Driven Python Tests using Pytest-BDD (Chapter 7.5)
Web UI tests are notoriously slow. When compared to typical tests in the industry, our DuckDuckGo search test is a bit of an anomaly for being so short. It’s common for companies to have hundreds to thousands of web UI tests that average about a minute per test. Consider the scale: 100 tests would take about 1 hour 40 minutes to run. 1000 tests would take over 16 hours to run! That’s too much time for a continuous integration / continuous delivery pipeline.
The only way to achieve truly continuous testing with web UI tests is to run them in parallel. Thankfully, that’s just a pytest plugin away. pytest-xdist lets you scale up by increasing the test thread count and scale out by distributing test execution to remote machines. Just be careful to avoid collisions in both the code and the system under test.
Here’s how to run the example project with 4 test threads:
$ pipenv run python -m pytest -n 4 ============================= test session starts ============================== platform darwin -- Python 3.7.3, pytest-4.6.2, py-1.8.0, pluggy-0.12.0 rootdir: /Users/andylpk247/Programming/automation-panda/python-webui-testing plugins: forked-1.0.2, html-1.20.0, xdist-1.28.0, metadata-1.8.0 gw0  / gw1  / gw2  / gw3  ......... [100%] =========================== 9 passed in 6.33 seconds ===========================
Go ahead and check out the next tip for taking your web UI testing with Python to the next level.