
- Selenium Webdriver Tutorial
- Home
- Introduction
- Installation
- Browser Navigation
- Identify Single Element
- Identify Multiple Elements
- Explicit and Implicit Wait
- Pop-ups
- Backward and Forward Navigation
- Cookies
- Exceptions
- Action Class
- Create a Basic Test
- Forms
- Drag and Drop
- Windows
- Alerts
- Handling Links
- Handling Edit Boxes
- Color Support
- Generating HTML Test Reports in Python
- Read/Write data from Excel
- Handling Checkboxes
- Executing Tests in Multiple Browsers
- Headless Execution
- Wait Support
- Select Support
- JavaScript Executor
- Chrome WebDriver Options
- Scroll Operations
- Capture Screenshots
- Right Click
- Double Click
- Selenium Webdriver Useful Resources
- Selenium WebDriver - Quick Guide
- Selenium WebDriver - Useful Resources
- Selenium WebDriver - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Generating HTML Test Reports in Python
We can generate HTML reports with our Selenium test using the Pytest Testing Framework. To configure Pytest, we have to run the following command:
pip install pytest.
Once the installation is done, we can run the command to check the Pytest version installed −
pytest –version
As a Pytest standard, the Python file containing the Pytest should start with test_ or end with _test. Also, all the test steps should be within a method whose name should start with test_.
To run a Pytest file, we can open the terminal and move from the current directory to the directory of the Pytest file that we want to execute. Then, run the command mentioned below −
py.test -v -s.
Let us look at a project structure following the Pytest Test Framework.

In the above image, it shows that the Pytest file has the name test_p.py and it contains a test method with the name test_SeleniumTest.
To generate a HTML report for a Selenium test, we have to install a plugin with the command: pip install pytest-html. To generate the report, we have to move from the current directory to the directory of the Pytest file that we want to execute. Then run the command: pytest --html=report.html.
After this command is successfully executed, a new file called the report.html gets generated within the project.

Right-click on the report.html and select the option Copy Path.

Open the path of the file copied in a browser, to get the HTML report.

The HTML report gives information of the Environment on which the test is executed. It also contains the information on test Summary and Results.