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_is_chromium(page):
    page.goto("https://www.google.com")
    page.type("input[name=q]", "Playwright GitHub")
    page.click("input[type=submit]")
    page.waitForSelector("text=microsoft/Playwright")

Fixtures

browser_name - session scope

A string that contains the current browser name.

browser - session scope

A Playwright browser instance for the whole test run.

context - function scope

A separate Playwright context instance for each new test.

page - function scope

A separate Playwright page instance for each new test.

launch_arguments - session scope

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

context_arguments - session scope

A fixture that you can define to overwrite the context arguments. 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_is_chromium(page):
    page.goto("https://www.google.com")
    # ...

Running only on a specific browser

import pytest

@pytest.mark.only_browser("chromium")
def test_is_chromium(page):
    page.goto("https://www.google.com")
    # ...

Handle base-url

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

def test_is_chromium(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_my_test(page: Page):
    page.goto("/admin")
    # ...

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.4.1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

pytest_playwright-0.0.4.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest-playwright-0.0.4.1.tar.gz
  • Upload date:
  • Size: 8.6 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.0 CPython/3.8.5

File hashes

Hashes for pytest-playwright-0.0.4.1.tar.gz
Algorithm Hash digest
SHA256 1d49edda8d8073b2c310ab5f4253905894e0dbd4b3246f101c0c4f865e60b6fd
MD5 13ed45a1bbfc41793338a37ad36e8909
BLAKE2b-256 34ab0dd070176fa31e383cdd1e96125481ac7b10e10559854d283fb55da62dd5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_playwright-0.0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 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.0 CPython/3.8.5

File hashes

Hashes for pytest_playwright-0.0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 043d36fc136922301bfe06fb9573260fca4a746bd0ee87983cc29ec318452ee6
MD5 901cc8dc1ec87e19a05871ea3aab21bb
BLAKE2b-256 f6a48661e320462e471a2da92a6a8d468260ca91dfcb2c80f549e4a6453991c9

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