I am writing some functional tests with Sauce Labs (Using Selenium + Webdriver + Nodejs). One of my test cases looks like the following:
it('Should Not Have Any Errors', function(done) {
browser
.get(host + '/test.live.cgi?view=pixelTest')
.elementById('errorHolder')
.text()
.should.eventually.equal('[]')
.nodeify(done);
});
How would I go about waiting 10 seconds between loading the page and checking the errorHolder element's text? I have been scanning through the api https://github.com/admc/wd/blob/master/doc/api.md but all of the wait functions look like they require an asserter function to test whether a given condition is true. I am trying to use waitFor(opts, cb) -> cb(err)
method but I am unsure of how to chain it with the promises. Can I do this?
Found the answer in the sleep function provided by webdriver. Now the code looks like this:
it('Should Not Have Any Errors', function(done) {
browser
.get(host + '/test.live.cgi?view=pixelTest')
.sleep(10000)
.elementById('errorHolder')
.text()
.should.eventually.equal('[]')
.nodeify(done);
});
await driver.sleep(n * 1000)
The above code works for me. Make sure that this code is inside an async function.
You can use:
.delay(10)
If you really have to use a delay though, consider defining it as a variable. You will have more control over delays throughout your code and it will be easier to search for if you need to refactor.
Edit to add:
you can also use:
.then(function () {
browser.waitForElementById('errorHolder');
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With