-2

I am writing some e2e tests with TestCafe, I am using the t.wait mechanism to wait for elements to appear on the page and in the dom, like this :

await t.wait(10000);
let sel=Selector("div").withAttribute('data-testid', 'something');
// continue with the test

This approach fails sometimes, and the test fails.
Is there a way to wait for that exact element to appear on the page ? Once the element appears, continue executing the test. I thought of doing something like this :

let sel=Selector("div").withAttribute('data-testid', 'something');
while (!sel.exists && !sel.visible) {
continue
}
// continue with the test

But there are obvious issues with this method, and it's not very elegant. So, does anyone else know a better solution for this ?

ElVincitore
  • 355
  • 2
  • 12

1 Answers1

0

Use the timeout option for Selector. For example:

let sel=Selector("div", { timeout: 10000 }).withAttribute('data-testid', 'something');
Alexey Popov
  • 1,033
  • 1
  • 4
  • 12