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指定されたAPIResponseAssertionsオブジェクトを作成します。
使用法
PlaywrightAssertions.assertThat(response).isOK();
引数
-
response
APIResponse#アサーションに使用するAPIResponseオブジェクト。
戻り値
assertThat(locator)
追加バージョン: v1.18指定されたLocatorAssertionsオブジェクトを作成します。
使用法
PlaywrightAssertions.assertThat(locator).isVisible();
引数
戻り値
assertThat(page)
追加バージョン: v1.18指定されたPageAssertionsオブジェクトを作成します。
使用法
PlaywrightAssertions.assertThat(page).hasTitle("News");
引数
戻り値
setDefaultAssertionTimeout
追加バージョン: v1.25Playwrightのアサーションのデフォルトタイムアウトを5秒から指定された値に変更します。
使用法
PlaywrightAssertions.setDefaultAssertionTimeout(30_000);
引数