https://github.com/vedro-universe/vedro-pw
Integrates Playwright for automated browser testing with customizable configuration options
https://github.com/vedro-universe/vedro-pw
vedro vedro-plugin
Last synced: 3 months ago
JSON representation
Integrates Playwright for automated browser testing with customizable configuration options
- Host: GitHub
- URL: https://github.com/vedro-universe/vedro-pw
- Owner: vedro-universe
- License: apache-2.0
- Created: 2023-10-08T10:37:45.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-09-29T19:15:03.000Z (8 months ago)
- Last Synced: 2025-12-29T03:22:13.841Z (5 months ago)
- Topics: vedro, vedro-plugin
- Language: Python
- Homepage:
- Size: 165 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# vedro-pw
[](https://codecov.io/gh/vedro-universe/vedro-pw)
[](https://pypi.python.org/pypi/vedro-pw/)
[](https://pypi.python.org/pypi/vedro-pw/)
[](https://pypi.python.org/pypi/vedro-pw/)
The `vedro-pw` plugin allows you to use [Playwright](https://playwright.dev/) within your [Vedro](https://vedro.io/) scenarios for end-to-end testing of web applications.
## Installation
Quick
For a quick installation, you can use a plugin manager as follows:
```shell
$ vedro plugin install vedro-pw
```
Manual
To install manually, follow these steps:
1. Install the package using pip:
```shell
$ pip install vedro-pw
```
2. Next, activate the plugin in your `vedro.cfg.py` configuration file:
```python
# ./vedro.cfg.py
import vedro
import vedro_pw
class Config(vedro.Config):
class Plugins(vedro.Config.Plugins):
class Playwright(vedro_pw.Playwright):
enabled = True
```
## Usage
Use the provided context functions in your scenarios to interact with Playwright:
- `launched_browser`: Launches a local or remote browser based on the configuration.
- `created_browser_context`: Creates a new browser context.
- `opened_browser_page`: Opens a new page in the browser context.
### Basic Example
Here's a simple Vedro scenario that opens the Playwright homepage and verifies the page title.
```python
import vedro
from vedro_pw import opened_browser_page, expect
class Scenario(vedro.Scenario):
subject = "Open Playwright homepage"
async def given(self):
self.page = await opened_browser_page()
async def when(self):
await self.page.goto("https://playwright.dev/")
async def then(self):
assert await expect(self.page).to_have_title("Playwright")
```
## Command-Line Options
The plugin adds several command-line arguments for flexibility:
| Option | Description | Default |
|------------------------|-------------------------------------------------------------------------|-----------------------|
| `--pw-browser` | Browser to use (`chromium`, `firefox`, `webkit`) | `chromium` |
| `--pw-headed` | Run browser in headed mode | `False` |
| `--pw-headless` | Run browser in headless mode | `True` |
| `--pw-slowmo` | Delay operations by specified milliseconds | `0` |
| `--pw-remote` | Connect to a remote browser instance | `False` |
| `--pw-remote-endpoint` | WebSocket endpoint for remote browser | `ws://localhost:3000` |
| `--pw-screenshots` | Screenshot capturing (`always`, `on-failure`, `on-reschedule`, `never`) | `never` |
| `--pw-video` | Video recording (`always`, `on-failure`, `on-reschedule`, `never`) | `never` |
| `--pw-trace` | Trace recording (`always`, `on-failure`, `on-reschedule`, `never`) | `never` |
| `--pw-device` | Emulate a specific device | `None` |
| `--pw-debug` | Enable Playwright debug mode by setting `PWDEBUG=1` | `False` |
| `--pw-open-last-trace` | Open the last captured Playwright trace after the test run | `False` |
### Example Usage
```shell
$ vedro run --pw-browser=firefox --pw-headed --pw-screenshots=on-failure
```
### Capture Modes
`CaptureMode` determines when to capture artifacts:
- `never`: Do not capture.
- `on-failure`: Capture only when a scenario fails.
- `on-reschedule`: Capture when a scenario is rescheduled.
- `always`: Always capture.
Artifacts like screenshots, videos, and traces are attached to the scenario results and can be used in reports.