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

PlaywrightAssertions

Playwrightは、Webファーストのアサーションを提供します。これにより、期待する条件が満たされるまで待機・再試行するアサーションを簡単に作成できます。

以下の例を検討してください

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は、セレクター.statusを持つノードが「Submitted」テキストを持つまで、そのノードを再テストします。条件が満たされるか、タイムアウトに達するまで、ノードを繰り返し再取得してチェックします。このタイムアウトはオプションとして渡すことができます。

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


メソッド

assertThat(response)

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

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

使用法

PlaywrightAssertions.assertThat(response).isOK();

引数

戻り値


assertThat(locator)

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

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

使用法

PlaywrightAssertions.assertThat(locator).isVisible();

引数

  • locator Locator#

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

戻り値


assertThat(page)

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

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

使用法

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

引数

  • page Page#

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

戻り値


setDefaultAssertionTimeout

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

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

使用法

PlaywrightAssertions.setDefaultAssertionTimeout(30_000);

引数

  • timeout double#

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