|
1 | | -# 🎭 Playwright Python Example 🎭 |
| 1 | +<div align="center"> |
2 | 2 |
|
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | -[](https://github.com/astral-sh/uv) |
8 | | -[](https://github.com/astral-sh/ruff) |
| 3 | +<img height="120" src="https://cdn.simpleicons.org/playwright/2EAD33"/> |
| 4 | + |
| 5 | +# Enterprise-Grade Playwright Python Architecture |
| 6 | +### The Ultimate Boilerplate for Scalable, Robust, and Modern UI Automation |
| 7 | + |
| 8 | +[](https://twitter.com/NirTal2) |
| 9 | +[](https://www.youtube.com/channel/UCQjS-eoKl0a1nuP_dvpLsjQ) |
| 10 | + |
| 11 | + |
| 12 | +[](https://github.com/astral-sh/uv) |
| 13 | +[](https://github.com/astral-sh/ruff) |
| 14 | + |
| 15 | +[View Live Report](https://nirtal85.github.io/Playwright-Python-Example/) • [Read The Docs](https://www.test-shift.com) • [Report Bug](https://github.com/nirtal85/Playwright-Python-Example/issues) |
| 16 | + |
| 17 | +</div> |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## 🚀 About The Project |
| 22 | + |
| 23 | +This repository is a **Production-Ready Reference Architecture** for building next-generation test automation using **Playwright** and Python. |
| 24 | + |
| 25 | +It goes beyond basic scripts to demonstrate a fully scalable framework with advanced features like Accessibility Testing (A11y), visual tracing, and cloud integration, tailored for modern DevOps pipelines. |
9 | 26 |
|
10 | 27 | <p align="center"> |
11 | 28 | <a href="https://automation.co.il/%d7%a7%d7%95%d7%a8%d7%a1-%d7%90%d7%95%d7%98%d7%95%d7%9e%d7%a6%d7%99%d7%94-%d7%a4%d7%99%d7%99%d7%aa%d7%95%d7%9f-python-automation/"> |
12 | | - <img src="resources/images/automation_college_playwright_course.jpeg" alt="Automation College - Playwright Python Course" /> |
| 29 | + <img src="resources/images/automation_college_playwright_course.jpeg" alt="Automation College - Playwright Python Course" width="600" style="border-radius: 10px;" /> |
13 | 30 | </a> |
14 | 31 | </p> |
15 | 32 |
|
| 33 | +### ✨ Key Features |
| 34 | +* **Modern Tooling:** Powered by `uv` for blazing fast package management and `Ruff` for linting. |
| 35 | +* **Accessibility First:** Integrated **Axe** scans to ensure your app is accessible to everyone. |
| 36 | +* **Deep Debugging:** Full integration with **Playwright Traces** and Video recording linked directly to Allure Reports. |
| 37 | +* **Cloud Scale:** Native integration with **BrowserStack** for cross-browser testing on real devices. |
| 38 | +* **CI/CD Optimization:** Parallel execution strategies and dynamic version syncing for GitHub Actions. |
| 39 | + |
| 40 | +--- |
| 41 | + |
16 | 42 | ## 📃 Articles written about this project |
17 | 43 |
|
| 44 | +This project implements the concepts discussed in the following **TestShift** articles: |
| 45 | + |
18 | 46 | * [Test Automation - How To Use Custom User Agent in Selenium Python or Playwright Python to Avoid Security Bots](https://www.test-shift.com/posts/test-automation-how-to-use-custom-user-agent-in-selenium-python-or-playwright-python-to-avoid-security-bots) |
19 | 47 | * [Test Automation - How to Use Dynamic Base URLs with Selenium And Playwright Python in GitHub Actions](https://www.test-shift.com/posts/test-automation-how-to-use-dynamic-base-urls-with-selenium-and-playwright-python-in-github-actions) |
20 | 48 | * [Test Automation - Maximizing Browser Window With Playwright Python And Pytest](https://www.test-shift.com/posts/test-automation-maximizing-browser-window-with-playwright-python-and-pytest) |
|
29 | 57 | * [From Open Source to Industry Sponsorship: The TestShift Journey with BrowserStack](https://www.test-shift.com/posts/from-open-source-to-enterprise-sponsorship-the-testshift-journey-with-browserstack) |
30 | 58 | * [From Selenium to Playwright: A Data-Driven Look at the Shifting Landscape of Test Automation](https://www.test-shift.com/posts/from-selenium-to-playwright-a-data-driven-look-at-the-shifting-landscape-of-test-automation) |
31 | 59 |
|
| 60 | +--- |
| 61 | + |
32 | 62 | ## 🛠️ Tech Stack |
33 | 63 |
|
34 | | -| Tool | Description | |
35 | | -|--------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------| |
36 | | -| [allure-pytest](https://pypi.org/project/allure-pytest/) | Allure reporting with your Pytest tests for better reporting | |
37 | | -| [axe-playwright-python](https://pypi.org/project/axe-playwright-python/) | Python library for running accessibility checks with Playwright | |
38 | | -| [playwright](https://pypi.org/project/playwright/) | Python library to automate the Chromium, WebKit, and Firefox browsers through a single API. | |
39 | | -| [pytest](https://pypi.org/project/pytest/) | Popular testing framework for Python | |
40 | | -| [pytest-base-url](https://pypi.org/project/pytest-base-url/) | Pytest plugin for setting a base URL for your tests | |
41 | | -| [pytest-playwright](https://pypi.org/project/pytest-playwright/) | Pytest plugin for Playwright integration for browser automation testing | |
42 | | -| [pytest-split](https://pypi.org/project/pytest-split/) | Pytest plugin which splits the test suite to equally sized sub suites based on test execution time. | |
43 | | -| [requests](https://pypi.org/project/requests/) | Versatile library for making HTTP requests in Python | |
| 64 | +| Tool | Description & Why We Use It | |
| 65 | +|-------------------------------------------------------------------|------------------------------------------------------------------| |
| 66 | +| [Playwright](https://pypi.org/project/playwright/) | The modern standard for reliable, flaky-free browser automation. | |
| 67 | +| [Pytest](https://pypi.org/project/pytest/) | The most powerful testing framework for Python. | |
| 68 | +| [Axe Playwright](https://pypi.org/project/axe-playwright-python/) | For automated accessibility (A11y) compliance testing. | |
| 69 | +| [Allure](https://pypi.org/project/allure-pytest/) | For beautiful, data-rich test reports including Traces & Video. | |
| 70 | +| [Pytest Split](https://pypi.org/project/pytest-split/) | To intelligently split test suites for parallel execution. | |
| 71 | +| [Requests](https://pypi.org/project/requests/) | For API interactions and test data setup. | |
| 72 | + |
| 73 | +### 🌐 Cloud Testing Provider |
44 | 74 |
|
45 | | -## 🌐 Browser Testing |
| 75 | +This project is powered by **[BrowserStack](https://www.browserstack.com)**, enabling high-scale cross-browser and mobile testing on real devices in the cloud. |
46 | 76 |
|
47 | | -This project is tested with [BrowserStack](https://www.browserstack.com), enabling cross-browser and mobile testing on real devices in the cloud. |
| 77 | +--- |
48 | 78 |
|
49 | | -## ⚙️ Setup Instructions |
| 79 | +## ⚙️ Getting Started |
50 | 80 |
|
51 | | -### Clone the project |
| 81 | +### 1. Clone |
52 | 82 |
|
53 | 83 | ```bash |
54 | 84 | git clone https://github.com/nirtal85/Playwright-Python-Example |
55 | 85 | cd playwright-python |
56 | 86 | ``` |
57 | 87 |
|
58 | | -### Create and activate a virtual environment then Install project dependencies |
| 88 | +### 2. Install (The Modern Way) |
| 89 | + |
| 90 | +We use uv for lightning-fast installations. |
| 91 | + |
| 92 | +Windows (PowerShell): |
| 93 | + |
59 | 94 |
|
60 | | -#### PowerShell installation in windows: |
61 | 95 | ```bash |
| 96 | +python -m pip install uv |
62 | 97 | python -m uv venv |
63 | 98 | .venv\Scripts\Activate.ps1 |
64 | | -python -m ensurepip --upgrade |
65 | | -python -m pip install uv |
66 | 99 | uv sync --all-extras --dev |
| 100 | +playwright install |
67 | 101 | ``` |
68 | 102 |
|
69 | | -#### For Mac: |
| 103 | +Mac/Linux: |
| 104 | + |
70 | 105 | ```bash |
71 | 106 | python3 -m pip install uv |
72 | 107 | uv venv |
73 | 108 | source .venv/bin/activate |
74 | 109 | uv sync --all-extras --dev |
75 | | -``` |
76 | | - |
77 | | -### Install playwright |
78 | | - |
79 | | -```bash |
80 | 110 | playwright install |
81 | 111 | ``` |
82 | 112 |
|
83 | | -## 🏃♂️ Running Tests |
| 113 | +## 🏃♂️ Execution |
| 114 | + |
| 115 | +Run all tests (Chromium by default): |
84 | 116 |
|
85 | 117 | ```bash |
86 | 118 | pytest |
87 | 119 | ``` |
88 | 120 |
|
89 | | -When no browser was selected then chrome will be used. |
90 | | - |
91 | | -* Run according to tags: |
| 121 | +Run specific suite (Tags): |
92 | 122 |
|
93 | 123 | ```bash |
94 | | -pytest -m <tag_name> |
| 124 | +pytest -m sanity |
95 | 125 | ``` |
96 | 126 |
|
97 | | -## 📊 Viewing Test Results |
98 | | - |
99 | | -### Install Allure Commandline To View Test results |
| 127 | +## 📊 Results, Traces & Debugging |
100 | 128 |
|
101 | | -#### For Windows: |
| 129 | +We use Allure for reporting and Playwright Traces for debugging. |
102 | 130 |
|
103 | | -Follow the instructions [here](https://scoop.sh/) to install Scoop.<br> |
104 | | -Run the following command to install Allure using Scoop: |
| 131 | +Viewing Reports Locally |
| 132 | +Windows (via Scoop): |
105 | 133 |
|
106 | 134 | ```bash |
107 | 135 | scoop install allure |
| 136 | +allure serve allure-results |
108 | 137 | ``` |
109 | 138 |
|
110 | | -#### For Mac: |
| 139 | +Mac (via Brew): |
111 | 140 |
|
112 | 141 | ```bash |
113 | 142 | brew install allure |
114 | | -``` |
115 | | - |
116 | | -### View Results Locally: |
117 | | - |
118 | | -```bash |
119 | 143 | allure serve allure-results |
120 | 144 | ``` |
121 | 145 |
|
122 | | -### View Results Online: |
123 | | - |
124 | | -[View allure results via Github pages](https://nirtal85.github.io/Playwright-Python-Example/) |
| 146 | +👉 [See a Live Example of the Report Here](https://nirtal85.github.io/Playwright-Python-Example/) |
125 | 147 |
|
126 | | -### View trace results: |
| 148 | +### 🕵️♀️ Using the Trace Viewer |
127 | 149 |
|
128 | | -1. Navigate to the [Playwright Trace Viewer](https://trace.playwright.dev/) |
129 | | -2. Locate the trace file stored under the test-results folder. This file is generated after running your tests. Click on the 'Upload' button in the Playwright Trace Viewer and select your trace file. |
130 | | -3. After uploading, the trace viewer will display a detailed timeline of events that occurred during your test. This includes network requests, JavaScript execution, and browser interactions. You can click on individual events for more details. |
| 150 | +Navigate to the Playwright Trace Viewer. |
131 | 151 |
|
132 | | -## ℹ️ View Help And Other CLI Options |
| 152 | +Drag & Drop the trace file (located in test-results/) generated after a failure. |
133 | 153 |
|
134 | | -```bash |
135 | | -pytest --help |
136 | | -``` |
137 | | - |
138 | | -### Pre Commit |
| 154 | +Time Travel: Move back and forth in the timeline to see exactly what happened (Network, DOM, Console). |
139 | 155 |
|
140 | | -#### Run Pre Commit Checks Automatically |
| 156 | +<div align="center"> |
141 | 157 |
|
142 | | -```bash |
143 | | -pre-commit install |
144 | | -pre-commit install --hook-type commit-msg |
145 | | -``` |
| 158 | +Found this project useful? |
| 159 | +If this architecture helped you solve a problem or save time, consider supporting the work! |
146 | 160 |
|
147 | | -#### Bump Pre Commit Hooks Version |
| 161 | +<a href="https://www.buymeacoffee.com/nirtal"> <img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" height="60" alt="Buy Me A Coffee" /> </a> |
148 | 162 |
|
149 | | -```bash |
150 | | -pre-commit autoupdate |
151 | | -``` |
152 | | - |
153 | | -#### Run Pre Commit Checks Manually On The Entire Project |
154 | | - |
155 | | -```bash |
156 | | -pre-commit run --all-files |
157 | | -``` |
158 | | -## ☕ Support |
| 163 | +<br /> |
159 | 164 |
|
160 | | -If you find this project helpful, you can support my work by buying me a coffee: |
| 165 | +Visit TestShift.com for more Architectural Insights |
161 | 166 |
|
162 | | -<p><a href="https://www.buymeacoffee.com/nirtal"> |
163 | | -<img align="left" src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" height="50" width="210" alt="Buy Me A Coffee" /> |
164 | | -</a></p><br><br> |
| 167 | +</div> |
0 commit comments