Search code examples
node.jsseleniumselenium-webdriverwebdriverchai

WebDriver wait n seconds


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?


Solution

  • 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);
      });