Playwright Test - Wait for checkbox / radio button state

Viewed 699

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.

2 Answers

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);
page.isChecked(selector, {timeout:5000})

Maybe this can help.

Related