thienphuong / playwright-with-typescript

0 stars 0 forks source link

Playwright Python BDD #11

Open thienphuong opened 8 months ago

thienphuong commented 8 months ago
  1. Install Python on Window with Choco
choco install python // v - 3.12.1
  1. Install the Pytest plugin:
pip install pytest-playwright

Update playwright

pip install pytest-playwright playwright -U
  1. Install the required browsers:
playwright install
thienphuong commented 8 months ago

Sample Test

import re
from playwright.sync_api import Page, expect

def test_has_title(page: Page):
    page.goto("https://playwright.dev/")

    # Expect a title "to contain" a substring.
    expect(page).to_have_title(re.compile("Playwright"))

def test_get_started_link(page: Page):
    page.goto("https://playwright.dev/")

    # Click the get started link.
    page.get_by_role("link", name="Get started").click()

    # Expects page to have a heading with the name of Installation.
    expect(page.get_by_role("heading", name="Installation")).to_be_visible()

Run tests in headed mode

pytest --headed
pytest --headed --browser chromium // choose from 'chromium', 'firefox', 'webkit'

pytest.ini


# content of pytest.ini
[pytest]
# Run firefox with UI
addopts = --headed --browser webkit