量角器片状

编程入门 行业动态 更新时间:2024-10-28 04:15:52
本文介绍了量角器片状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我维护一个复杂的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 and chromedriver with it
  • turn off Angular animations
  • use dragons browser.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();

  • 增加量角器和茉莉花超时
  • 控制流程来缓慢调整量角器 (不确定它是否适用于4.0.0,请测试)
  • 在有问题的地方手动调用 browser.waitForAngular(); 。我不知道为什么这会有所帮助,但我已经看到报告确实有助于修复一个不稳定的测试。
  • 使用 jasmine done()回调。例如,这可能有助于在<$ c中调用完成之前不启动 it()块$ c> beforeEach()
  • 从 onPrepare()函数返回一个承诺。这通常有助于确保为测试运行做好准备。
  • 使用 protractor-flake 包将自动重新运行失败的测试。更像是对问题的快速解决方法
  • increase the Protractor and Jasmine timeouts
  • slow Protractor down by tweaking the Control Flow (not sure if it works for 4.0.0, please test)
  • manually call 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.
  • use the jasmine done() callback in your specs. This may help to, for example, not to start the it() block until done is called in beforeEach()
  • return a promise from the onPrepare() function. This usually helps to make sure things are prepared for the test run
  • use protractor-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.

    更多推荐

    量角器片状

    本文发布于:2023-11-22 23:10:14,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1619286.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:量角器   片状

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!