アサーション
アサーションの一覧
カスタム Expect メッセージ
カスタム Expect メッセージは、expect
関数の 2 番目の引数として指定できます (例:)
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)