メインコンテンツにスキップ

PlaywrightAssertions

Playwrightは、期待される条件が満たされるまで待機して再試行するアサーションを作成するための便利なメソッドを備えたWeb-Firstアサーションを提供します。

次の例を考えてみましょう

import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;

public class TestExample {
// ...
@Test
void statusBecomesSubmitted() {
// ...
page.locator("#submit-button").click();
assertThat(page.locator(".status")).hasText("Submitted");
}
}

Playwrightは、フェッチされたNodeが"Submitted"というテキストを持つまで、セレクター.statusを持つノードを再テストします。条件が満たされるか、タイムアウトに達するまで、ノードを再フェッチして何度もチェックし続けます。このタイムアウトはオプションとして渡すことができます。

デフォルトでは、アサーションのタイムアウトは5秒に設定されています。


メソッド

assertThat(response)

バージョン v1.18 で追加 playwrightAssertions.assertThat(response)

指定されたAPIResponseAPIResponseAssertionsオブジェクトを作成します。

使用方法

PlaywrightAssertions.assertThat(response).isOK();

引数

戻り値


assertThat(locator)

バージョン v1.18 で追加 playwrightAssertions.assertThat(locator)

指定されたLocatorLocatorAssertionsオブジェクトを作成します。

使用方法

PlaywrightAssertions.assertThat(locator).isVisible();

引数

  • locator Locator#

    アサーションに使用するLocatorオブジェクト。

戻り値


assertThat(page)

バージョン v1.18 で追加 playwrightAssertions.assertThat(page)

指定されたPagePageAssertionsオブジェクトを作成します。

使用方法

PlaywrightAssertions.assertThat(page).hasTitle("News");

引数

  • page Page#

    アサーションに使用するPageオブジェクト。

戻り値


setDefaultAssertionTimeout

バージョン v1.25 で追加 playwrightAssertions.setDefaultAssertionTimeout

Playwrightアサーションのデフォルトタイムアウトを5秒から指定された値に変更します。

使用方法

PlaywrightAssertions.setDefaultAssertionTimeout(30_000);

引数

  • timeout double#

    タイムアウト(ミリ秒)。