Skip to content

Commit b053069

Browse files
authored
Add polling and timeout assertions in Playwright test q
1 parent c9aad5e commit b053069

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

pages/playwright/index.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,30 @@ <h2>Usefull snippets</h2>
5858

5959
test.use({ actionTimeout: 2000 });
6060
await page.waitForTimeout(50);
61+
await expect.poll(async () => {
62+
const selectedItems = await querySelector(page, selector);
63+
return await selectedItems.innerHTML();
64+
}).toEqual(data);
65+
await expect.poll(async () => {
66+
return await page.locator('.status-message').textContent();
67+
}, {
68+
// Custom message if it times out
69+
message: 'The status message did not update in time',
70+
// Total time to keep trying (in milliseconds)
71+
timeout: 10000,
72+
// How long to wait between attempts
73+
intervals: [500, 1000, 2000],
74+
}).toEqual('Success');
75+
await expect(async () => {
76+
const selectedItems = await querySelector(page, selector);
77+
const content = await selectedItems.innerHTML();
78+
79+
// A standard assertion inside the block
80+
expect(content).toEqual(data);
81+
}).toPass({
82+
timeout: 10000,
83+
intervals: [500]
84+
});
6185

6286
// extra step for codegen
6387
await expect(page.locator("body")).toHaveCount(1);

0 commit comments

Comments
 (0)