Browser.sleep 和 browser.pause 没有被执行

Browser.sleep and browser.pause do not get executed

我是量角器和打字稿的新手,我现在正在为 PoC 试用该框架。但是,我想知道为什么 browser.sleep() 或 browser.pause() 在以下情况下不会执行?
第一步通过后测试立即退出。

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");
});

我知道使用 browser.sleep 是一种不好的做法,我不会在我的代码中使用它,但是,它在构建测试时很有用。

Protractor 使用 WebdriverJS 与浏览器进行交互,webdriverJS 中的所有操作都是异步的。 Protractor 使用一个名为 promise manager 的 webdriverJS 功能,它处理所有这些异步 promise,以便它们按照编写的顺序执行,并且测试对于测试创建者来说变得更具可读性。 webdriverJS 已弃用此功能,但是随着 async/await 的引入,promises 变得更易于管理。出于这个原因,建议不要让你的测试依赖于承诺管理器,因为它最终将在 Protractor 使用的即将推出的 webdriverJS 版本中不可用。

我之所以提到所有这些,是因为从您使用 async/await 看来,您已经在 conf 中将 SELENIUM_PROMISE_MANAGER 设置设置为 false。这意味着这些承诺不再由量角器解决,需要在您的测试中手动处理。

您的等待未执行,因为在您的异步函数中没有等待该承诺。

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");
});

希望对您有所帮助。