This tutorial provides a step-by-step guide on using Python and Playwright for WebUI test automation.
- Introduction
- Prerequisites
- Getting Started
- Running UI Tests
- Running API Tests
- Running All Tests
- Debugging Tests
- Allure Report
- License
In this tutorial, we will explore how to use Python and Playwright to automate WebUI tests.
Before getting started, make sure you have the following prerequisites installed:
- Python 3.x
- PIP
python3 -m ensurepip
- venv
pip install virtualenv
To get started with Python and Playwright, follow these steps:
- Clone or download this repository.
- Open a terminal and navigate to the project directory.
- Create and activate isolated environment by running following commands
python3 -m venv venv
For Linux & Mac run
source venv/bin/activate
For Windows run
venv\Scripts\activate.bat
- Install the project dependencies by running the following command:
pip3 install -r requirements.txt
- Running UI tests in headless mode Chrome
python3 -m pytest -m webtest tests --verbose
- Running UI tests in headed mode & specific browser(chromium,firefox,webkit)
python3 -m pytest -m webtest tests --browser webkit --headed --verbose
- Running UI tests in headed mode in all browsers in parallel
python3 -m pytest -m webtest tests --numprocesses auto --browser chromium --browser firefox --browser webkit --headed --verbose
Running API tests using Playwright
python3 -m pytest -m apitest -s tests --screenshot on --verbose
- Running All tests using Playwright in headless mode
python3 -m pytest -s tests --screenshot on --verbose
- Running All tests using Playwright in headed mode
python3 -m pytest -s tests --screenshot on --verbose --headed
In order to launch Playwright inspector and debug specific tests run following commands
PWDEBUG=1 python3 -m pytest -s -k test_basic_duckduckgo_search --verbose
By default test summary will be posted into commandline
In order to generate HTML report using Allure reporting framework run tests with --alluredir
parameter
python3 -m pytest -s --alluredir=allure-results tests --numprocesses auto --browser chromium --browser firefox --browser webkit --screenshot on --video on --headed --verbose
And the generate and open report in browser by running
allure serve -h localhost
This project is licensed under the MIT License.