Playwright 설치

Python 3.9 이상 버전을 가지고 있다고 가정함
가능하면 Anaconda 환경에서 실행할 것
다음을 실행함

pip install pytest-playwright
playwright install

Hello World

테스트 파일을 만들어 실행하자.
각각의 함수는 Page 오브젝트를 첫번째 파라미터로 받는다.
테스트 절차는 함수의 작성 순서대로 실행된다.

해당 파일의 이름을 test_example.py라고 하자.

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"))
    print("Test 1 complete")

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()
    print("Test 2 complete")

이 테스트를 실행하려면 pytest를 실행한다.

python -v -s

물론 pytest -v -s test_example.py 이렇게 직접 해도 된다.