All Projects → mxschmitt → pytest-playwright

mxschmitt / pytest-playwright

Licence: MIT license
Pytest plugin to write Playwright tests with ease. Provides fixtures to have a page instance for each individual test and helpful CLI options for headless browsers.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to pytest-playwright

Usaspending Api
Server application to serve U.S. federal spending data via a RESTful API
Stars: ✭ 166 (+1085.71%)
Mutual labels:  pytest
Pytest Chinese Doc
pytest 官方文档的中文翻译,但不仅仅是单纯的翻译,也包含自己的理解和实践。
Stars: ✭ 192 (+1271.43%)
Mutual labels:  pytest
Best Of Python Dev
🏆 A ranked list of awesome python developer tools and libraries. Updated weekly.
Stars: ✭ 243 (+1635.71%)
Mutual labels:  pytest
Awesome Pytest
A curated list of awesome pytest resources
Stars: ✭ 170 (+1114.29%)
Mutual labels:  pytest
Cookiecutter Pytest Plugin
A Cookiecutter template for pytest plugins 💻
Stars: ✭ 181 (+1192.86%)
Mutual labels:  pytest
Pytest Clarity
A plugin to improve the output of pytest with colourful unified diffs
Stars: ✭ 209 (+1392.86%)
Mutual labels:  pytest
Allure Pytest
Deprecated, please use https://github.com/allure-framework/allure-python instead
Stars: ✭ 159 (+1035.71%)
Mutual labels:  pytest
agent-python-pytest
Framework integration with PyTest
Stars: ✭ 86 (+514.29%)
Mutual labels:  pytest
Django Test Migrations
Test django schema and data migrations, including migrations' order and best practices.
Stars: ✭ 188 (+1242.86%)
Mutual labels:  pytest
Pytest Selenium
Plugin for running Selenium with pytest
Stars: ✭ 246 (+1657.14%)
Mutual labels:  pytest
Pytest Flask Sqlalchemy
A pytest plugin for preserving test isolation in Flask-SQLAlchemy using database transactions.
Stars: ✭ 168 (+1100%)
Mutual labels:  pytest
Seleniumbase
A Python framework that inspires developers to become better test automation engineers. 🧠💡
Stars: ✭ 2,520 (+17900%)
Mutual labels:  pytest
Pytest Qt
pytest plugin for Qt (PyQt4, PyQt5 and PySide) application testing
Stars: ✭ 210 (+1400%)
Mutual labels:  pytest
Pudb
Full-screen console debugger for Python
Stars: ✭ 2,267 (+16092.86%)
Mutual labels:  pytest
ci-testing-python
Sample Microservice App in Python for Testing using pytest, uber/doubles, tox on CI servers like Jenkins and Travis CI using Docker + Docker-Compose for test environment.
Stars: ✭ 37 (+164.29%)
Mutual labels:  pytest
Pytest Tricks
😏 Tips and Tricks for the Python Testing Tool
Stars: ✭ 162 (+1057.14%)
Mutual labels:  pytest
Cookiecutter Cms
Python-centric Cookiecutter for Molecular Computational Chemistry Packages
Stars: ✭ 197 (+1307.14%)
Mutual labels:  pytest
stock reminder bot
A twitter bot that reminds you of stock and crypto predictions
Stars: ✭ 25 (+78.57%)
Mutual labels:  pytest
playwright-ci
☁️ Set up Playwright in CI
Stars: ✭ 27 (+92.86%)
Mutual labels:  playwright
Httprunner
One-stop solution for HTTP(S) testing, written in Python.
Stars: ✭ 2,628 (+18671.43%)
Mutual labels:  pytest

Pytest Playwright Plugin (moved over to microsoft/pytest-playwright)

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")
    # ...
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].