Skip to main content

A pytest wrapper with fixtures for Playwright to automate web browsers

Project description

Pytest Playwright Plugin

CI PyPI Coverage Status black

A Pytest wrapper for Playwright to automate web browsers (Chromium, Firefox, WebKit).

Features

  • Have a separate new page and context for each test with Pytest fixtures
  • Run your end-to-end tests on multiple browsers by a CLI argument
  • Run them headful with the --headful argument to debug them easily
  • Using base-url to only use the relative URL in your Page.goto calls

Installation

pip install pytest-playwright

Basic example for more see the examples sections as a reference.

def test_example_is_working(page):
    page.goto("https://example.com")
    page.waitForSelector("text=Example Domain")
    page.click("text=More information")

Fixtures

browser_name - session scope

A string that contains the current browser name.

browser - session scope

A Playwright browser instance for the session.

context - function scope

A separate Playwright context instance for each new test.

page - function scope

A separate Playwright page instance for each new test.

browse_type_launch_args - session scope

A fixture that you can define to overwrite the launch arguments for launch(). It should return a Dict.

browse_context_args - session scope

A fixture that you can define to overwrite the context arguments for newContext(). It should return a Dict.

is_chromium, is_firefox, is_webkit - session scope

A fixture which is a boolean if a specific execution is made by the specified browser.

CLI arguments

--browser

By default, the tests run on the Chromium browser. You can pass multiple times the --browser flag to run it on different browsers or a single time to run it only on a specific browser.

Possible values: chromium, firefox, webkit

--headful

By default, the tests run in headless mode. You can pass the --headful CLI flag to run the browser in headful mode.

Examples

Skipping by browser type

import pytest

@pytest.mark.skip_browser("firefox")
def test_visit_example(page):
    page.goto("https://example.com")
    # ...

Running only on a specific browser

import pytest

@pytest.mark.only_browser("chromium")
def test_visit_example(page):
    page.goto("https://example.com")
    # ...

Handle base-url

Start Pytest with the base-url argument. Example: pytest --base-url http://localhost:8080

def test_visit_example(page):
    page.goto("/admin")
    # -> Will result in http://localhost:8080/admin

Using Mypy types for auto completion

from playwright.sync_api import Page

def test_visit_admin_dashboard(page: Page):
    page.goto("/admin")
    # ...

Special thanks

Max Schmitt for creating and maintaining the Pytest Playwright plugin.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-playwright-0.0.5.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

pytest_playwright-0.0.5-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file pytest-playwright-0.0.5.tar.gz.

File metadata

  • Download URL: pytest-playwright-0.0.5.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for pytest-playwright-0.0.5.tar.gz
Algorithm Hash digest
SHA256 bc9b8b1a7d246c170bfa8d07554f5bec7aa52ce03954dbeb68932312e5b5960e
MD5 befed88c20394d694ab74ed83b1ff37a
BLAKE2b-256 172542ce28ff52445df830d7d9987617797e7927ed93d579b58bdba63f0e9574

See more details on using hashes here.

File details

Details for the file pytest_playwright-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: pytest_playwright-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for pytest_playwright-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6d9cdc1f85f67a1061bc7e50f32f7829a7002446675c610cfad0b71585fa198c
MD5 3d84af0aee7ac3a31fd51c27dd33211f
BLAKE2b-256 dddf86e5787621d4fa9d39c223787d4fb44664bb0ab3a68e456b4c9f23d52ed8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page