HTML test report in Pytest

In this blog, we are working on how to generate the Test Execution Report in the Pytest file. 

As a pre-requisite we have to check whether the following dependencies are installed or not:

  1. Project setup. 
  2. Run pip list in PyCharm terminal to check whether playwright is installed or not. 

As shown in the above picture playwright should be installed in the project. 

If the Playwright is not installed refer to Web Automation Testing using Playwright.


Playwright supports the Pytest Framework. We can use the same Pytest command for both Sync and Async APIs. 

To install Pytest we have to run the following command in the terminal. 

pip install Pytest-playwright 

After the successful installation of Pytest run pip list in terminal to check whether the Pytest is installed successfully or not.  

If Pytest is not installed then check out the blog on How to run the single test case in Pytest

In Playwright we can get the Test Execution Report in 2 ways 

  1. During the run time on the terminal. 
  2. Automatically generate by creating the pytest.ini file. 

1. During the run time on the terminal:

Using Terminal that is while executing the Pytest command we can mention one more argument as –html=Test_Eecution_Report_Name.html 

As shown in the above example we are explicitly providing the command as –html=report.html. If we don’t provide the path then the reports are stored in the project root file. 

2. Automatically generate using pytest.ini file:

We can configure the pytest.ini file to auto-generate the Test Report at a specific path. The pytest.ini file is automatically executed by the Pytest engine. When we run the command as Pytest in the terminal. 

As shown in the above example the Test Execution Report is automatically generated by the Pytest engine and stored at a specific path. We don’t need to provide commands explicitly in the terminal.  If we don’t provide the path then the reports are stored in the project root file. 

Test Case:

Step 1: – Launch the Browser. 

Step 2: – Navigate to 

Step 3: – Fill the text in the input box as welcome to close ops in playwright

Step 4: – Close the page and browser. 

from playwright.sync_api import Playwright, sync_playwright 
with sync_playwright() as page: 
    def test_demo(playwright: Playwright): 
        browser = playwright.chromium.launch(headless=False, slow_mo=1000) 
        page = browser.new_page() 
        page.locator(".gLFyf.gsfi").fill("welcome to close ops in playwright") 

Running file using Pytest command 

HTML Report 

In the above Test Case, the HTML Report is auto-generated using the pytest.ini file 

Pros and Cons:


1. Built-In command line (CLI) tools: Playwright has huge CLI tools such as Test Generator, Trace viewer, and Inspect Selector. 

2. Built-In Locators: Playwright provides Built-In Filtering locators, to reduce execution time, such as looping to dynamic Web table, Dynamic dropdown, etc. 

3. Cross-Browser Support:

Playwright supports all types of browsers, and we don’t need to download any dependencies manually, playwright auto downloads the dependencies as per the requirement.  

4. Cross Programming Language Support: Playwright supports different programming languages such as python, Node.js, Java, .NET 

5. Auto waits for Elements until an element is visible on DOM: Playwright auto handles the waits, as by default it waits for 3000ms for the Element to be interactable and all the related checks to elements are done. We don’t need to use any type of implicit or explicit wait. 

6. Easy to capture Screenshots: In Playwright we can capture the element screenshot or full-page screenshot just by using the page.screenshot()  method which is one line statement. 

7. Supports API Testing: Playwright provides support for API Testing, so when we need the API to be used in Web Automation, we can use it directly as it works on Python’s request module. 


1. Lack of documentation and confusing concepts in documents: Playwright documentation is not clear, and it creates confusion while implementing the concepts/Topics. 

2. Lack of proper examples on topics such as auto-login, and POM Implementation: Playwright doesn’t have the proper examples on concepts/Topics. 

3. Community is small for support: As the playwright is new in the market, if issues are encountered then the solution for that issue on the internet is not available directly. 

4. Unnecessary APIs to record the screen and auto-login: To record the screen and a few of the best features such as auto-login, we have to open the browser in context mode which makes the implementation complex and complicated. 

5. No Direct methods or API to perform iteration on elements and to perform further operations: We can’t implement the easy programming logic on DOM elements such as if there is a dynamic web table, so we can’t directly iterate over the table, collect the text and perform the required operation on it, which is the biggest drawback on the playwright. 

6. The strictness of locators: The strictness of locators makes the Tester logic complex, such as if we have the dynamic table and if we want to perform a click operation on a specific element, then we can’t use looping and condition statements to filter out the unwanted elements and click on the required element.