Browser.sleep和browser.pause不会执行 [英] Browser.sleep and browser.pause do not get executed

查看:130
本文介绍了Browser.sleep和browser.pause不会执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是量角器和打字稿的新手,我现在正在尝试PoC的框架。但是,我想知道为什么在以下情况下browser.sleep()或browser.pause()无法执行?

测试在第一步通过后立即退出。

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

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

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.

推荐答案

量角器使用WebdriverJS与浏览器进行交互,并且webdriverJS中的所有操作都是异步的。量角器使用一种称为诺言管理器的webdriverJS功能,该功能处理所有这些异步诺言,以便按编写顺序执行它们,并使测试创建者更容易理解测试。
webdriverJS不赞成使用此功能,但是随着async / await的引入,使promise变得更易于管理。因此,建议不要让测试依赖Promise Manager,因为它最终将在Protractor使用的即将发布的webdriverJS版本中不可用。

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.

我提到了所有这是因为,通过使用异步/等待,它似乎已经在conf中将SELENIUM_PROMISE_MANAGER设置为false。这意味着这些承诺将不再由量角器解决,而需要在测试中手动处理。

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

希望有帮助。

这篇关于Browser.sleep和browser.pause不会执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆