Browser.sleep and browser.pause do not get executed

冷暖自知 提交于 2019-12-24 20:38:14

问题


I am new to protractor and typescript and I am trying out the framework now for a PoC. However, I was wondering why the browser.sleep() or browser.pause() do not get executed in the following scenario?
The test just exits right away after the first step passes.

Given(/^I access the  Catalogue page$/, async () => {
    await expect(browser.getTitle()).to.eventually.equal("Sign in to your account");
});


Then(/^I should see the product$/, async () => {
    browser.sleep(5000);
    //expect(cataloguePage.allProducts.getText()).to.be("Fixed Product");
});

I know it is a bad practice to use browser.sleep and I will not use it in my code, however, it is useful while building the tests.


回答1:


Protractor uses WebdriverJS to interact with the browser and all actions in webdriverJS are asynchronous. Protractor uses a webdriverJS feature called the promise manager which handles all these async promises so that they are executed in the order they are written and the tests become more readable for the test creator. This feature is being deprecated by webdriverJS however as promises have become easier to manage with the introduction of async/await. For this reason it is recommended to move away from having your tests rely on the promise manager as it will eventually be unavailable in upcoming webdriverJS version which Protractor uses.

I mentioned all of this because it appears, from you use of async/await, you already have the SELENIUM_PROMISE_MANAGER setting set to false in your conf. This means these promises are no longer being resolved by protractor and need to be handled manually in your test.

Your wait is not executing because that promise is no being awaited within you async function.

Given(/^I access the  Catalogue page$/, async () => {
    await expect(browser.getTitle()).to.eventually.equal("Sign in to your account");
});


Then(/^I should see the product$/, async () => {
    await browser.sleep(5000);
    //expect(cataloguePage.allProducts.getText()).to.be("Fixed Product");
});

Hope that helps.



来源:https://stackoverflow.com/questions/54330750/browser-sleep-and-browser-pause-do-not-get-executed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!