1
0

Playwrightでテストが成功する状態になるまで待機したいときにはtoPassを使う

Posted at

expect.toPass

 PlaywrightではLocatorが見つからない場合は自動で待機してくれますが、そのLocatorのテキスト等が違う場合はテストが失敗してしまうことがありますが、expect.toPassを使用することでブロック内が合格するまでテストをリトライさせることができます。
 以下の例は配列testListの長さが10になるまテストをリトライし、一定時間成功しないとタイムアウトになり失敗します。

await expect(async () => {
    expect(testList.length).toBe(10);
}).toPass();

 リトライのインターバルやタイムアウトは以下のように指定できます。

await expect(async () => {
  expect(testList.length).toBe(10);
}).toPass({
  intervals: [1000, 2000, 10000],
  timeout: 60000
});

おわり

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0