Reputation: 3922
I copypasted the example code from WebdriverIO's documentation about the 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');
});
Even if the #someText
element doesn't change its text to "I am now different", the client does not wait and reports the test as passing.
Actually, using the following code has the exact same behaviour although I explicitely return false (=it should never exit the waitUntil command):
it('should wait until text has changed', function () {
client.waitUntil(function () {
return false;
}, 5000, 'expected text to be different after 5s');
});
What am I missing? What am I doing wrong?
I am using [email protected]
and webdriverio": "^4.6.2
Upvotes: 1
Views: 9384
Reputation: 10702
The test may be returning before waitUntil has finished. It may be that you are not dealing with the asynchronous nature of this library. Try the following async code:
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');
});
Upvotes: 1
Reputation: 2269
Are you using the wdio
test runner? If so, is 'sync' mode set to true? If not, then you'll need to return the 'client' to the mocha test:
it('should wait until text has changed', function () {
return client.waitUntil(function () {
return false;
}, 5000, 'expected text to be different after 5s');
});
Within the test, you'd need to use .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');
});
});
Upvotes: 0