Protractor moves on to next test without waiting

风流意气都作罢 提交于 2019-12-01 12:23:51

The way I understand the then()-functionality, it starts an async task. Therefore any line of code outside the then()-function will be continued as soon as then() is entered. Read more about here, here and here.

Further exist several challenges around browser.get() and browser.driver.get() in terms of promise-resolving, as it's not clear, whether the page to load can be synchronized with the ControlFlow. Therefore a browser.driver.get() isn't always forcing Protractor to wait. Read more about here and here

Your test now combines these two issues in a way.

I suggest to try browser.waitForAngular(); in your solution to trigger protractor to actually wait until all promises are resolved:

describe('...', () => {
   it('...', () => {
       expect(element.all(by.css(...).count()).toBe(9);

       element.all(by.css(...)).get(0).isDisplayed().then((state) => {
          expect(state).toBeTruthy();
       });
       //instead of using done to explicitly announce the "function finished"
       //use browser.waitForAngular() to let Protractor wait for any promises to be resolved.
       browser.waitForAngular(); 
   });
}

describe('', () => {
    beforeAll(() => {
         // .click() returns a promise, so Protractor waits for it to be resolved
         //element(by.css('.go-home').click();  
         browser.driver.get('/');   // doesn't return a promise
         browser.waitForAngular();  // triggers Protractor to wait for $http and promises resolved.
    });
    ...
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!