本文介绍了waitForAngularEnabled 是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我很好奇 waitForAngularEnabled() 是如何工作的?尽管它看起来并不复杂,但是,我无法在任何地方得到任何满意的答案.所以希望有人能帮助我清除.

I am curious how does waitForAngularEnabled() work?Though it doesn't seem complicated, however, I couldn't get any satisfied answers anywhere. So hopefully someone helps me get cleared.

我的目标是检查标准并暂停/锁定运行测试,直到满足标准.下面以案例为例.

My goal is to check criteria and pause/lock running test until the criteria is meet. Here are cases for example.

A.暂停正在运行的测试并等待页面加载

A. to pause running test and wait until page gets loaded

    ...
    let theElement = ...;
    browser.waitForAngularEnabled(false);
    browser.wait(protractor.ExpectedConditions.presenceOf(theElement));

B.使用 browser.wait(),与 A 实现类似目的的替代方法

B. to use browser.wait(), the alternative way for similar purpose with A

    browser.wait(() => {
        browser.waitForAngularEnabled(false);
        return browser.isElementPresent(by.id('the-element-id'));
    }, timeout); // timeout may not be given

所以问题是:

  1. 调用 waitForAngularEnabled(false) 后会发生什么?(在我的情况下,一旦满足条件或超时)
  2. 我应该恢复 waitForAngularEnabled(true) 以继续正常测试吗?
  3. 如果我应该做,放在哪里?

希望通过一些背景原则得到明确的答案.

Hope to get clear answers with some background principle.

谢谢!

推荐答案

1.调用 waitForAngularEnabled(false) 后会发生什么?(在我的情况下,一旦满足条件或超时)

根据经验,我发现这似乎导致 Protractor 仅表现为 Webdriver.它不会等待 Angular 安定下来"(没有挂起的 HTTP 请求或视图更新),这是 true 的行为.相反,如果您使用 false 设置,您将需要使用 ExpectedConditions 或类似方法来验证前提条件以可靠地执行测试步骤,就像使用普通 Webdriver 测试一样.

Empirically I have found that this seems to cause Protractor to behave as merely Webdriver. It does not wait for Angular to "settle down" (no pending HTTP requests or view updates), which is the behavior for true. Instead, if you use the false setting, you will need to use ExpectedConditions or similar approaches in order to verify preconditions to execute test steps reliably, just as you would with an ordinary Webdriver test.

2.我应该恢复 waitForAngularEnabled(true) 以继续正常测试吗?

是的.但是,我发现在 Protractor 5.1.1 和 5.1.2 中,无论是否使用控制流,在同一执行中在整个测试中分散不同的 waitForAngularEnabled 值似乎会产生不可预测的结果;也就是说,启用状态不遵循其他 Protractor/Webdriver 调用的相同异步语义.到目前为止,我的结论是你不能在同一次执行中可靠地混合 waitForAngularEnabled(false) 和 waitForAngularEnabled(true).我怀疑这是一个 Protractor 错误,但我还没有开发一个简单可靠的测试来证明它支持提交 Protractor 问题.此处可能存在相关问题,现已关闭但未完全诊断.

Yes. However, I have found that in Protractor 5.1.1 and 5.1.2, whether using control flow or not, scattering different waitForAngularEnabled values throughout your tests in the same execution seems to yield unpredictable results; that is, the enabled state does not follow the same asynchronous semantics of other Protractor/Webdriver calls. So far, my conclusion is that you cannot reliably mix waitForAngularEnabled(false) and waitForAngularEnabled(true) in the same execution. I suspect that this is a Protractor bug, but I have not yet developed a simple and reliable test to prove it in support of submitting a Protractor issue. There was a possibly related issue here, now closed but incompletely diagnosed.

3.如果我应该做,放在哪里?

之前"您进行量角器/Webdriver 调用需要恢复等待 Angular 语义.但是,如上所述,尚不清楚您能否可靠地保证此类调用将真正在 true 设置的上下文中进行.

"Before" you make Protractor/Webdriver calls that require restoring the waiting-for-Angular semantics. However, as mentioned above, it's not clear that you can reliably guarantee that such calls will truly be made in the context of the true setting.

如果您必须有一些使用 false 和其他 true 的测试,您可以在单独的执行中运行它们(单独的进程;不要使用相同的 protractorng e2e 命令).采用这种方法时,我没有遇到任何问题.

If you must have some tests that use false and others true, you could run them in separate executions (separate processes; don't run them with the same protractor or ng e2e command). I have encountered no problems when that approach is taken.

这篇关于waitForAngularEnabled 是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 00:24