我从WebdriverIO关于waitUntil
(http://webdriver.io/api/utility/waitUntil.html)的文档中复制了示例代码:
it('should wait until text has changed', function () {
client.waitUntil(function () {
return client.getText('#someText') === 'I am now different';
}, 5000, 'expected text to be different after 5s');
});
即使#someText
元素没有将其文本更改为"我现在不同",客户端也不会等待并将测试报告为传递。
实际上,使用以下代码具有完全相同的行为,尽管我明确地返回false (=它应该永远不会退出waitUntil命令):
it('should wait until text has changed', function () {
client.waitUntil(function () {
return false;
}, 5000, 'expected text to be different after 5s');
});
我错过了什么?我做错了什么?
我正在使用node@v7.2.1
和webdriverio": "^4.6.2
答案 0 :(得分:0)
您使用的是wdio
测试跑步者吗?如果是,is 'sync' mode set to true?如果没有,那么你需要将'client'返回到mocha测试:
it('should wait until text has changed', function () {
return client.waitUntil(function () {
return false;
}, 5000, 'expected text to be different after 5s');
});
在测试中,您需要使用.then
:
it('should wait until text has changed', function () {
return client
.waitUntil(function () {
return false;
}, 5000, 'expected text to be different after 5s')
.then(function () {
console.log('i am here now');
});
});
答案 1 :(得分:0)
可能在waitUntil完成之前返回测试。可能您没有处理此库的异步性质。尝试以下异步代码:
it('should wait until text has changed', async () => {
await client.waitUntil(async () => {
const currentText = await client.getText('#someText');
return currentText === 'I am now different';
}, 5000, 'expected text to be different after 5s');
});