如何获得量角器可靠的结果? [英] How to have protractor reliable results?

查看:37
本文介绍了如何获得量角器可靠的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Protractor (v 1.3.1) 为我的 Angular 1.2.26 应用程序运行 E2E 测试.

I'm using Protractor (v 1.3.1) to run E2E tests for my Angular 1.2.26 application.

但有时,测试可以,有时则不行.似乎有时检查是在显示更新之前完成的(或类似同步"问题).我尝试了很多选择:

But sometimes, tests are ok, sometimes not. It seems that sometimes the check is done before display is updated (or something like "synchronisation" problem). I try many options :

  • 添加browser.driver.sleep指令,
  • 使用 browser.executeScript('$.fx.off = true')
  • 禁用效果
  • 添加browser.waitForAngular() 说明
  • add browser.driver.sleep instructions,
  • disable effects with browser.executeScript('$.fx.off = true')
  • add browser.waitForAngular() instructions

没有成功.

使用量角器进行可靠的 E2E 测试的最佳实践是什么?

What are the bests practice to have reliables E2E tests with protractor?

JM.

推荐答案

每次遇到类似问题,我都会使用 browser.wait()"预期条件"(在量角器 1.7 中引入).有一组内置的预期条件通常就足够了,但您可以轻松定义自定义预期条件.

Every time I have similar issues, I'm using browser.wait() with "Expected Conditions" (introduced in protractor 1.7). There is a set of built-in expected conditions that is usually enough, but you can easily define your custom expected conditions.

例如,等待一个元素变得可见:

var EC = protractor.ExpectedConditions;
var e = element(by.id('xyz'));

browser.wait(EC.visibilityOf(e), 10000);
expect(e.isDisplayed()).toBeTruthy();

一些注意事项:

browser.wait(EC.visibilityOf(e), 10000, "Element 'xyz' has not become visible");

  • 您可以将 EC 设置为指向 protractor.ExpectedConditions 的全局可用变量.将此行添加到配置中的 onPrepare():

  • you can set EC to be a globally available variable pointing to protractor.ExpectedConditions. Add this line to the onPrepare() in your config:

    onPrepare: function () {
        global.EC = protractor.ExpectedConditions;
    }
    

  • 作为自定义预期条件的示例,请参阅此答案

    这篇关于如何获得量角器可靠的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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