如何等待一个量角器最终处理结束测试一个事件? [英] How to wait for a event to be processed in a protractor end to end test?

查看:224
本文介绍了如何等待一个量角器最终处理结束测试一个事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很简单的 AngularJs 1.4.8 的前端:

在这里输入的形象描述

在表格填充和确定按钮为pressed新的人加入到表中。

的形式是在 addingPersonController 和表是在 allPersonsController ,都是孩子的下 masterController

在添加一个用户(确定点击)发生以下情况:


  1. POST 请求被发送到服务器,以添加新的人。

  2. personAddedEvent $发出发出 addingPersonController masterController

  3. masterController 广播一个 updatePersonsEvent allPersonsController

  4. allPersonsController 为了让所有的人员和更新表发送GET请求到服务器。

我有一个量角器端到端测试行使这种情况下,问题是,我无法弄清楚如何等待整个过程完成前检查断言和测试始终失败。

用户界面的工作,当手动测试,我曾尝试与量角器测试等待:


  • browser.wait(函数(){},超时);

  • browser.sleep(MS);

  • 。点击(),那么();

他们没有工作。

有没有办法来等待这样一个过程检查断言之前完成?


解决方案

有一些similiar问题与我的端到端的测试了。有可以添加几个变通的。依靠的情况下,主要是由于某种非响应超时(量角器/硒和浏览器之间的同步丢失)的。它就像一个挂在电脑,原因是缺乏资源(无论是 GPU /显存 RAM CPU )。这导致内置的等作品的角度需做的量角器失去了跟踪。并运行规范之前,应该运行。

下面是列表,我会建议你尝试:


  1. 使用内置的等待角快速解决问题的大部分时间。但是,这没有什么可处理量角器/硒和浏览器之间的同步丢失。

browser.waitForAngular();

<醇开始=2>
  • 使用 ExpectedConditions browser.wait() 这始终是最好的,因为这将确保所有情况下工作。即使外面角度的环境。不好的事情有关,这是......这是相当长的键入

  • browser.wait(ExpectedConditions.textToBe presentInElement($('#someId),人的名字),10000);

    编辑:错别字,让答案更容易理解

    I have very simple AngularJs 1.4.8 Front-End:

    When the form is filled and the OK button is pressed the new person is added to the table.

    The form is in the addingPersonController and the table is in the allPersonsController, both are childs under the masterController.

    When a user is added(OK clicked) the following happens:

    1. a POST request is sent to the server in order to add the new person.
    2. a personAddedEvent is emitted with $emit from the addingPersonController to the masterController
    3. the masterController broadcasts an updatePersonsEvent to the allPersonsController
    4. the allPersonsController sends a GET request to the server in order to get all the persons and update the table.

    I have a protractor end to end test that exercises this case, the problem is that I can not figure out how to wait for the whole process to finish before to check the assertions and the test always fails.

    The UI works when tested manually and I have tried to wait in the protractor test with:

    • browser.wait(function(){}, timeout);
    • browser.sleep(ms);
    • .click().then();

    None of them worked.
    Is there a way to wait for such a process to complete before checking the assertions?

    解决方案

    Got some similiar issues with my e2e tests too. There are couple of work-arounds can be added. Depend on situations , mostly due to some sort of non-response timeout (lost synchronization between protractor/selenium and browser). It is like a hang of the PC, cause by lack of resource (either GPU/VRAM, RAM or CPU). And this cause the built-in "wait for angular works to be done" of protractor lost its tracking. And run the spec before it should be ran.

    Here is the list I will suggest you to try:

    1. use built-in wait for angular Quick and solve the problem most of the time. But it will have nothing to deal with the lost synchronization between protractor/selenium and browser.

    browser.waitForAngular();

    1. use ExpectedConditions with browser.wait() This is always the best because it will sure work for all case. Even outside angular environment. Bad thing about this is... it is quite long to type

    browser.wait( ExpectedConditions.textToBePresentInElement( $('#someId'), "Person's Name"), 10000);

    EDIT: typos and make answer more understandable

    这篇关于如何等待一个量角器最终处理结束测试一个事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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