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

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

    You don't need to wait. Protractor automatically waits for angular to be ready and then it executes the next step in the control flow.

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

    Depending on what you want to do, you can try:

    browser.waitForAngular();

    or

    btnLoginEl.click().then(function() {
      // do some stuff 
    }); 
    

    to solve the promise. It would be better if you can do that in the beforeEach.

    NB: I noticed that the expect() waits for the promise inside (i.e. getCurrentUrl) to be solved before comparing.

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

    Use this I think it's better

       *isAngularSite(false);*
        browser.get(crmUrl);
    
    
        login.username.sendKeys(username);
        login.password.sendKeys(password);
        login.submit.click();
    
        *isAngularSite(true);*
    

    For you to use this setting of isAngularSite should put this in your protractor.conf.js here:

            global.isAngularSite = function(flag) {
            browser.ignoreSynchronization = !flag;
            };
    
    0 讨论(0)
  • 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

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

    In this case, you can used:

    Page Object:

        waitForURLContain(urlExpected: string, timeout: number) {
            try {
                const condition = browser.ExpectedConditions;
                browser.wait(condition.urlContains(urlExpected), timeout);
            } catch (e) {
                console.error('URL not contain text.', e);
            };
        }
    

    Page Test:

    page.waitForURLContain('abc#/efg', 30000);
    
    0 讨论(0)
  • 2020-11-29 00:50

    you can do something like this

    emailEl.sendKeys('jack');
    passwordEl.sendKeys('123pwd');
    
    btnLoginEl.click().then(function(){
    browser.wait(5000);
    });

    0 讨论(0)
提交回复
热议问题