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.
Tutorial Chapters
- 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)
- You’re here → Create Pytest HTML Test Reports (Chapter 7.1)
- 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)
When pytest runs at the command line, it sometimes prints an unhelpful wall of text. Visual reports are a much better way to consume test result information, especially for non-developers. Adding the pytest-html plugin to your test project enables you to print pretty HTML reports with one simple command line option.
Reports will look like this:
When it comes to Python and Selenium/Appium functional tests there is an easy open-source solution provided by TestProject that automatically creates the HTML and PDF reports for you (out of the box, no additional configuration needed). Simply follow this Github link to learn more about it, or read through this great tutorial to get started.
Reports will look like this:
Go ahead and check out the next tip for taking your web UI testing with Python to the next level.
So, in order to generate a report we can run our tests via command line like this: pytest –html=report.html
But what if I want to generate report and run my tests via any IDE (VS Code for example) using Pytest not a command line? How can I build my test then? How can I write a function/method to run report.html then?
Thank you.
Managed to solve this.
You need to create pytest.ini file in the project folder and add this:
[pytest]
addopts = -v –html=report.html –self-contained-html
how can run pytest.ini file
pytest will automatically discover the pytest.ini file (and other config files) if they are in the directory from which pytest is invoked.
Hi ,
I tried this and I am getting an error – ERROR: file not found: –html=report.html
I am running pytest test cases through command line but for report I do not want to use command line argument. Thus tried above solution. But its not working/
How to generated html folder using dynamic path (currentdateandtime)
I’m not sure if that is possible, but you can check here: https://github.com/pytest-dev/pytest-html. In the worst case, you could post-process file names using a script.