问题描述
我用量角器(V 1.3.1),以我的角度1.2.26应用程序运行E2E测试。
I'm using Protractor (v 1.3.1) to run E2E tests for my Angular 1.2.26 application.
但有时候,测试都OK,有时没有。这似乎显示更新之前,有时检查完成(或像同步的问题)。
我尝试了很多选项:
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 =真正的')
- 添加
browser.waitForAngular()
说明
- add
browser.driver.sleep
instructions, - disable effects with
browser.executeScript('$.fx.off = true')
- add
browser.waitForAngular()
instructions
没有成功。
什么是最好成绩的做法有reliables端到端测试,量角器?
What are the bests practice to have reliables E2E tests with protractor?
JM。
推荐答案
每当我有类似的问题,我使用的<一个href=\"http://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.wait\"><$c$c>browser.wait()$c$c>与(的介绍)。有一组内置的预期条件下,通常是足够了,但您可以轻松定义自定义条件的预期。
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
。该行添加到上prepare()
在你的配置:
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;
}
作为一个自定义的预期条件的示例,请参阅
这篇关于如何拥有量角器可靠的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!