Protractor flakiness

前端 未结 4 708
忘掉有多难
忘掉有多难 2021-02-02 00:58

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 t

4条回答
  •  不要未来只要你来
    2021-02-02 01:24

    Just Say No to More End-to-End Tests!

    That said, here are the few things you can do to tackle our mutual merciless "flakiness" enemy:

    • 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();
      
    • maximize the browser window (to avoid random element not visible or not clickable errors). Put this to onPrepare():

      browser.driver.manage().window().maximize();
      
    • 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

    There are also other problem-specific "tricks" like slow typing into the text box, clicking via JavaScript etc.

提交回复
热议问题