vitalets/playwright-bdd

Question: can you confirm that expect.toPass assertion is working with playwright BDD - cucumber style/playwright style

markov1983 opened this issue · 3 comments

For my project purposes, I use expect.toPass assertion from the playwright.

It's not being triggered when used in a cucumber style (haven't tried the playwright one but I know it's working on one other repo which does not use playwright bdd). The block of code is just not retried inside that assertion, after 60 seconds it just times out (without retrying)

Example:

Then(
  'some description',
  async function (field) {

    await expect(async () => {


      await expect(locator).toBeVisible();
    }).toPass({
      // Probe, wait 1s, probe, wait 2s, probe, wait 10s, probe, wait 10s, probe
      // ... Defaults to [100, 250, 500, 1000].
      intervals: [2_000, 5_000, 10_000],
      timeout: 80_000,
    });
  },
); 

It seems that global expect timeout is respected in this case which is set in playwright.config.ts (60000ms) and not the one that is set on the assertion.

Also, the code is not retried in intervals so I am wondering have I did everything right in terms of config. @vitalets can you confirm it works on your end (cucumber style)

packages used:

"@playwright/test": "^1.45.0",
"playwright-bdd": "^7.0.1",
"node": "20.15.0"

The problem here is that await expect(locator).toBeVisible() is auto-waiting assertion, so it performs probes under the hood itself.
To fix the code you can use locator.isVisible:

  await expect(async () => {
    const isVisible = await page.getByRole("dialog").isVisible();
    expect(isVisible).toBe(true);
  }).toPass({
    // Probe, wait 1s, probe, wait 2s, probe, wait 10s, probe, wait 10s, probe
    // ... Defaults to [100, 250, 500, 1000].
    intervals: [2_000, 5_000, 10_000],
    timeout: 80_000,
  });

@vitalets Thx a lot, will try :)

Feel free to re-open if needed.