0

I am coming from the world of Python and I am a bit confused on how I can add sleeps into my test (only been at JS for a week). I understand that sleeps are not best practice, though I would just like to learn how it can be done. Currently I have a test which launches the browser then immediately fails because the load times on the page. Just for debugging purposes, I would like to pause the test for a couple seconds. This is currently what I have that does not work. Thank you for your responses.

var assert = require('assert');

describe('basic login', function() {
it('verify user is able to login', function () {
    browser.url('http://localhost:3000');
    var elem = browser.element('div.accounts-dropdown > div.dropdown-toggle > span');
    //elem.waitForVisible(2000); //not working
    //elem.waitForExist(3000); //not working
    return browser.waitUntil (function async() {
        elem.click();
        browser.setValue('//input', 'sy7nktvw@localhost');
        browser.setValue('//div[2]/input', 'kU3SPn75');
        browser.click("//button[@type='submit']");
        assert('//li/div/button');

    }, 50000, 'something_test');
    //browser.click('div.accounts-dropdown > div.dropdown-toggle > span');
});

});

Josh
  • 460
  • 1
  • 5
  • 20
  • 3
    There are no sleeps, you'd have to [block the thread](http://stackoverflow.com/questions/20967006/how-to-create-a-sleep-delay-in-nodejs-that-is-blocking) and hang the browser, which is why it's a big no-no. Use an event handler that fires when the page has loaded instead, for instance `window.onload` etc. – adeneo Jul 25 '16 at 18:49

2 Answers2

0

browser.pause(milliseconds) will do exactly what you want.

browser.pause(1000);
-2

I ended up getting the following to work:

function sleep(time, callback) {
var stop = new Date().getTime();
while(new Date().getTime() < stop + time) {
    ;
}
callback();

}

Josh
  • 460
  • 1
  • 5
  • 20