protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Protractor browser.sleep() is not getting executed.

Open gamecheck80 opened this issue 10 years ago • 3 comments

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

gamecheck80 avatar Jul 01 '16 19:07 gamecheck80

@gamecheck80 remove single quotes in the

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

anilreddy avatar Jul 03 '16 05:07 anilreddy

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!

cnishina avatar Jul 06 '16 22:07 cnishina

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

itLead797 avatar Oct 19 '18 13:10 itLead797