量角器片状 [英] Protractor flakiness
问题描述
我维护一个复杂的Angular(1.5.x)应用程序,使用Protractor(2.5.x)进行E2E测试。我遇到了这种方法的问题,主要表现在测试看起来很脆弱的方式。在一个拉取请求中完美运行的测试在另一个拉取请求中失败。这涉及简单的定位器,例如by.linkTest(...)。我调试了失败的测试,应用程序位于正确的页面上,链接存在且可访问。
I maintain a complex Angular (1.5.x) application that is being E2E tested using Protractor (2.5.x). I am experiencing a problem with this approach, which presents primarily in the way the tests seem flaky. Tests that worked perfectly well in one pull request fail in another. This concerns simple locators, such as by.linkTest(...). I debugged the failing tests and the app is on the correct page, the links are present and accessible.
还有其他人遇到过这些一致性问题吗?了解原因或解决方法?
Has anyone else experienced these consistency problems? Knows of a cause or workaround?
推荐答案
那就是说,你可以采取一些措施来解决我们共同无情的诡异敌人:
That said, here are the few things you can do to tackle our mutual merciless "flakiness" enemy:
- 更新到最新的量角器(目前为4.0.0),它还带来了最新的
selenium
和chromedriver
with it - 关闭Angular动画
-
使用
龙browser.wait( )
,其中包含一组内置或自定义预期条件。这可能是迄今为止解决问题的最可靠方法。不幸的是,这是用例和特定问题,您需要在有问题的地方修改您的实际测试。例如,如果您需要单击某个元素,请等待它可以点击:
- update to the latest Protractor (currently 4.0.0) which also brings latest
selenium
andchromedriver
with it - turn off Angular animations
use
dragonsbrowser.wait()
with a set of built-in or custom Expected Conditions. This is probably by far the most reliable way to approach the problem. Unfortunately, this is use-case and problem specific, you would need to modify your actual tests in the problematic places. For example, if you need to click an element, wait for it to be clickable:
var EC = protractor.ExpectedConditions;
var elm = $("#myid");
browser.wait(EC.elementToBeClickable(elm), 5000);
elm.click();
最大化浏览器窗口(以避免随机元素不可见或者不是可点击的错误)。把它放到 onPrepare()
:
maximize the browser window (to avoid random element not visible or not clickable errors). Put this to onPrepare()
:
browser.driver.manage().window().maximize();
browser.waitForAngular();
。我不知道为什么这会有所帮助,但我已经看到报告确实有助于修复一个不稳定的测试。 done()
回调。例如,这可能有助于在<$ c中调用完成
之前不启动 it()
块$ c> beforeEach() onPrepare()
函数返回一个承诺。这通常有助于确保为测试运行做好准备。 protractor-flake
包将自动重新运行失败的测试。更像是对问题的快速解决方法
browser.waitForAngular();
in problematic places. I am not sure why this helps but I've seen reports where it definitely helped to fix a flaky test.done()
callback in your specs. This may help to, for example, not to start the it()
block until done
is called in beforeEach()
onPrepare()
function. This usually helps to make sure things are prepared for the test runprotractor-flake
package that would automatically re-run failed tests. More like a quick workaround to the problem还有其他特定问题的技巧,例如在文本框中输入,点击通过JavaScript 等。
There are also other problem-specific "tricks" like slow typing into the text box, clicking via JavaScript etc.
这篇关于量角器片状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!