Skip to content

m9810223/playwright-async-pytest

Repository files navigation

Playwright Async Pytest -- ASYNC Pytest plugin for Playwright

pypi

There an official playwright plugin for pytest: PyPI / playwright-pytest / intro. But if you need an async version, here is it!

Installation

pip install pytest-playwright-async

Example

Here you can find more examples.

# conftest.py
import asyncio

import pytest_asyncio


@pytest_asyncio.fixture(scope='session')
def event_loop():  # https://pytest-asyncio.readthedocs.io/en/latest/reference/fixtures.html#fixtures
    policy = asyncio.get_event_loop_policy()
    loop = policy.new_event_loop()
    yield loop
    loop.close()
# test_playwright.py
import pytest
from playwright.async_api import Page


@pytest.mark.asyncio
async def test_page_async(page_async: Page):
    await page_async.goto('https://playwright.dev/')
    assert (
        await page_async.title()
        == 'Fast and reliable end-to-end testing for modern web apps | Playwright'
    )