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.

1
  • Is the checkbox connected to an API call? you can use page.waitForResponse in that case. Commented Apr 5, 2022 at 12:39

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

Comments

0
page.isChecked(selector, {timeout:5000})

Maybe this can help.

2 Comments

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'
In that case you can create fluent wait, and ping by intervals.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.