Protractor : How to wait for page complete after click a button?

后端 未结 9 740
抹茶落季
抹茶落季 2020-11-29 00:16

In a test spec, I need to click a button on a web page, and wait for the new page completely loaded.

emailEl.sendKeys(\'jack\');
passwordEl.sendKeys(\'123pwd         


        
相关标签:
9条回答
  • 2020-11-29 00:52
    browser.waitForAngular();
    
    btnLoginEl.click().then(function() { Do Something });
    

    to solve the promise.

    0 讨论(0)
  • 2020-11-29 00:53

    I just had a look at the source - Protractor is waiting for Angular only in a few cases (like when element.all is invoked, or setting / getting location).

    So Protractor won't wait for Angular to stabilise after every command.

    Also, it looks like sometimes in my tests I had a race between Angular digest cycle and click event, so sometimes I have to do:

    elm.click();
    browser.driver.sleep(1000);
    browser.waitForAngular();
    

    using sleep to wait for execution to enter AngularJS context (triggered by click event).

    0 讨论(0)
  • 2020-11-29 00:53

    I typically just add something to the control flow, i.e.:

    it('should navigate to the logfile page when attempting ' +
       'to access the user login page, after logging in', function() {
      userLoginPage.login(true);
      userLoginPage.get();
      logfilePage.expectLogfilePage();
    });
    

    logfilePage:

    function login() {
      element(by.buttonText('Login')).click();
    
      // Adding this to the control flow will ensure the resulting page is loaded before moving on
      browser.getLocationAbsUrl();
    }
    
    0 讨论(0)
提交回复
热议问题