2

I currently have an issue where I need to wait for a checkbox / radio button to be "checked" before I proceed with my testing.

If I assert the checkbox is checked the test fails because it doesn't have the checked state immediately after the action.

How does one go about this through playwright commands. Yes I can add a hardcoded timeout, but I feel like there is a better way.

OrdinaryKing
  • 411
  • 1
  • 7
  • 16

2 Answers2

1

It looks like in version 1.21.0 of playwright they have added a polling assertion:

// Poll the method until it returns an expected result.
await expect.poll(async () => {
  const response = await page.request.get('https://api.example.com');
  return response.status();
}).toBe(200);
OrdinaryKing
  • 411
  • 1
  • 7
  • 16
0
page.isChecked(selector, {timeout:5000})

Maybe this can help.

Gaj Julije
  • 1,538
  • 15
  • 32
  • 1
    Thanks, I have tried this (Added the timeout too and no luck), however, it still fails. I think its because the locator is visible, its just returns false, or true in the cases where I'm waiting for it to become 'unchecked' – OrdinaryKing Apr 04 '22 at 12:18
  • In that case you can create fluent wait, and ping by intervals. – Gaj Julije Apr 05 '22 at 14:17