In this blogpost, we will discuss how to run Playwright automation tests using Python programming language on Visual Studio code IDE.
I’ll put the post in three points as shown below:
- Set Up
- Test Automation Framework with Playwright and Python
- Integrate Automation Tests with CI
1. Set Up:
Do the following installations on your Mac.
- Install Node: Run the command "brew install node" on your terminal.
- Install Python3: Go to Python3-Download
Install Playwright & pytest
Install Playwright Browsers
playwright install
Create and Activate Virtual Environment
python3 -m venv venv
Install Pytest Plugin for Playwright Fixtures
pip install pytest-playwright
2. Test Automation Framework with Playwright and Python:
A basic boilerplate code using Page Object Design framework is created for this post and the folder structure, page objects, pages, tests and test report are shown below.
The Folder structure looks like this
Pages : The individual web pages used for the test.
base_page.py - Contains all the web actions used by the tests and will
be inherited by the the other pages like login page, cart page, Inventory
page etc..
test_end_to_end.py
The test will call the needed pages and in-turn in the pages will inherit the base page functions/methods to perform the web actions. Assertions are checked and put in place.
Run the Tests locally:
For all tests : pytest --html=reports/report.html
For specific test : pytest tests/test_login.py -s -v
Test Report:
From your Report Folder 'reports/report.html'
3. Integrate Automation Tests with CI
GitHub Actions:-
Run the Tests on GitHub Actions
Pipeline:
Create a folder .github/workflows and inside this folder create a yml file with name "playwright.yml" file as shown below
Click on the first one
Click on test as shown below
Happy Automation Testing Guys :)!
No comments:
Post a Comment