Skip to main content

After this course i will be a decent playwright and pytest developer

Project description

Playwright and Pytest

Install Pytest Plugin

pip install pytest-playwright

Install the required browsers

playwright install

test_example.py

test example

Running the Example Test

pytest

Using Test Hooks

import pytest
from playwright.sync_api import Page, expect

@pytest.fixture(scope="function", autouse=True)
def before_each_after_each(page: Page):
    
    print("before the test runs")

    # Go to the starting url before each test.
    page.goto("https://playwright.dev/")
    yield
    
    print("after the test runs")

def test_main_navigation(page: Page):
    # Assertions use the expect API.
    expect(page).to_have_url("https://playwright.dev/")

Running tests headed

pytest --headed

Running tests on different browsers and multiple browser

pytest --browser webkit
pytest --browser webkit --browser firefox

Running specific tests

pytest test_login.py

To run a set of test files pass in the names of the test files that you want to run.

pytest tests/test_todo_page.py tests/test_landing_page.py

To run a specific test pass in the function name of the test you want to run.

pytest -k test_add_a_todo_item

Run tests in Parallel

pytest --numprocesses 2

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

playwright_project-0.0.5.tar.gz (2.4 kB view hashes)

Uploaded Source

Built Distribution

playwright_project-0.0.5-py3-none-any.whl (3.0 kB view hashes)

Uploaded Python 3

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