アサーション
アサーションのリスト
カスタムExpectメッセージ
`expect`関数の2番目の引数としてカスタムexpectメッセージを指定できます。例:
expect(page.get_by_text("Name"), "should be logged in").to_be_visible()
expectが失敗した場合、エラーは次のようになります。
def test_foobar(page: Page) -> None:
> expect(page.get_by_text("Name"), "should be logged in").to_be_visible()
E AssertionError: should be logged in
E Actual value: None
E Call log:
E LocatorAssertions.to_be_visible with timeout 5000ms
E waiting for get_by_text("Name")
E waiting for get_by_text("Name")
tests/test_foobar.py:22: AssertionError
カスタムタイムアウトの設定
アサーションのカスタムタイムアウトをグローバルまたはアサーションごとに指定できます。デフォルトのタイムアウトは5秒です。
グローバルタイムアウト
conftest.py
from playwright.sync_api import expect
expect.set_options(timeout=10_000)
アサーションごとのタイムアウト
test_foobar.py
from playwright.sync_api import expect
def test_foobar(page: Page) -> None:
expect(page.get_by_text("Name")).to_be_visible(timeout=10_000)