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.
📍 If you are looking for a single Python Package for Android, iOS and Web Testing – there is also an easy open source solution provided by TestProject. With a single executable, zero configurations, and familiar Selenium APIs, you can develop and execute robust Python tests and get automatic HTML test reports as a bonus! All you need is:
pip install testproject-python-sdk. Simply follow this Github link to learn more about it, or read through this great tutorial to get started.
- Web UI Testing Made Easy with Python, Pytest and Selenium WebDriver (Overview)
- 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)
- Parallel Test Execution with Pytest (Chapter 7.2)
- You’re here → 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)
The test project we wrote runs WebDriver on the local test machine. Local WebDriver instances work well for small projects but not for large projects. Typical test machines can run only a few WebDriver instances in parallel before stalling. And running tests on different combinations of browsers, operating systems, and versions becomes tough.
Enter the Grid: Selenium Grid can scale out web UI testing with the use of remote WebDrivers. The Grid has a hub and a bunch of nodes. Instead of launching a WebDriver instance locally, tests will make a request to the hub for an instance with specific options like browser type and OS. The hub will then find an available node for the request criteria. The node will run the WebDriver instance and send responses back to the test machine. A sizable grid can easily handle multiple tests in parallel (à la pytest-xdist).
Selenium Grid is part of the Selenium Standalone Server. It is implemented in Java and released as a JAR file. You don’t need to do any Java programming to use it, but you will need the JDK to run it. Follow the instructions on the Selenium Grid wiki to set up the hubs and nodes. It’s pretty easy to set up if you have access to a few machines. If you don’t want to set up your own Grid, you could also opt for could-based testing platforms like TestProject.
Go ahead and check out the next tip for taking your web UI testing with Python to the next level.