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

后端 未结 9 788
抹茶落季
抹茶落季 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:43

    With Protractor, you can use the following approach

    var EC = protractor.ExpectedConditions;
    // Wait for new page url to contain newPageName
    browser.wait(EC.urlContains('newPageName'), 10000);
    

    So your code will look something like,

    emailEl.sendKeys('jack');
    passwordEl.sendKeys('123pwd');
    
    btnLoginEl.click();
    
    var EC = protractor.ExpectedConditions;
    // Wait for new page url to contain efg
    ptor.wait(EC.urlContains('efg'), 10000);
    
    expect(ptor.getCurrentUrl()).toEqual(url + 'abc#/efg');
    

    Note: This may not mean that new page has finished loading and DOM is ready. The subsequent 'expect()' statement will ensure Protractor waits for DOM to be available for test.

    Reference: Protractor ExpectedConditions

提交回复
热议问题