当我需要等待元素变得可见时,我可以简单地将选择器作为函数调用,如下所示:
await element.with({ visibilityCheck: true })();
但我怎样才能等待一个元素消失呢?
要等待元素消失,您可以使用我们内置的断言等待机制。请参见文档 https://devexpress.github.io/testcafe/documentation/test-api/assertions/#smart-assertion-query-mechanism有关其工作原理的更多信息。
import { Selector } from 'testcafe';
fixture `fixture`
.page `http://localhost/testcafe/`;
test('test 2', async t => {
//step 1
//wait for the element to disappear (assertion with timeout)
await t.expect(Selector('element').exists).notOk({ timeout: 5000 });
//next steps
});
或者您可以使用ClientFunction https://devexpress.github.io/testcafe/documentation/test-api/obtaining-data-from-the-client/:
import { ClientFunction } from 'testcafe';
fixture `fixture`
.page `http://localhost/testcafe/`;
const elementVisibilityWatcher = ClientFunction(() => {
return new Promise(resolve => {
var interval = setInterval(() => {
if (document.querySelector('element'))
return;
clearInterval(interval);
resolve();
}, 100);
});
});
test('test 1', async t => {
//step 1
//wait for the element to disappear
await elementVisibilityWatcher();
//next steps
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)