Protractor: Protractor browser.sleep() is not getting executed.

Created on 1 Jul 2016  ·  3Comments  ·  Source: angular/protractor

In the below as you can see that the browser.sleep is supposed to be executed if the client is XYZ, but still it is not getting executed. If i put any console.log after the browser.sleep statement, that statement is getting executed (i can see the statement) but the browser.sleep is not really waiting even though how much the sleep time i increase.

Why is the browser.sleep is not working? How do i make it wait if the client XYZ?

           if (testproperties.client == 'ABC'){
                browser.ignoreSynchronization = false;
                browser.waitForAngular();
                browser.ignoreSynchronization = true;    
            }
            else if (testproperties.client == 'XYZ'){
                browser.sleep('35000');
            };

Most helpful comment

@gamecheck80 remove single quotes in the

// use like this
browser.sleep(35000);

All 3 comments

@gamecheck80 remove single quotes in the

// use like this
browser.sleep(35000);

Really quick for clarification: browser.sleep returns a promise. Looking into this closely:

  • browser.sleep calls webdriver.sleep
  • webdriver.sleep calls for the control flow to do a timeout
  • timeout calls the delay which in the end calls the setTimeout method and this could be a string as long as that string is a number.

browser.sleep('35000') is an acceptable input.

Because browser.sleep returns a promise, it will only appear that it works if you wait for the promise to finish.

describe('browser', function() {
  it('should sleep', function() {
    browser.get('http://angularjs.org');

    // does not work
    // browser.sleep(10000);
    // console.log('waited 10 seconds?');
    // this does not work and "waited 10 seconds?" appears immediately after navigating

    // after sleeping then print "waited 10 seconds"
    browser.sleep(10000).then(function() {
      console.log('waited 10 seconds');
    });
  });
});

Hopefully this helps. For more help, please ask your support questions on StackOverflow, Google Group discussion list, or Gitter. For more information please reference https://github.com/angular/protractor/blob/master/CONTRIBUTING.md#questions

Thank you!

browser.sleep(10000).then(function() {
console.log('waited 10 seconds');
});
Using this with Angular 6 and protractor version 5.4.1 does not work, at least that's what I'm seeing

Was this page helpful?
0 / 5 - 0 ratings