【问题标题】:Protractor - run test again if fails量角器 - 如果失败,再次运行测试
【发布时间】:2022-02-07 21:24:21
【问题描述】:

我正在使用 shell 脚本运行量角器测试。 我想确保如果测试失败(退出代码!= 0)那么它将再次运行 - 最多三倍。 我已经在使用 Teamcity,但 Teamcity 会发送“失败”电子邮件,然后才会重试。我希望测试在发送消息之前运行 3 次。 这是我脚本的一部分:

if [ "$#" -eq 0 ];
then
/usr/local/bin/protractor proactor-config.js --suite=sanity

现在我想以某种方式检查退出代码是否为 0 而不是 - 再次运行。 谢谢。

【问题讨论】:

    标签: shell protractor angularjs-e2e false-positive


    【解决方案1】:

    我为此编写了一个名为protractor flake 的小模块。它可以通过cli使用

    # defaults to 3 attempts
    protractor-flake -- protractor.conf.js
    

    programatically

    这里的一件好事是它只会重新运行失败的规范文件,而不是你的测试套件。

    在量角器问题队列中有一个长期存在的feature request。它可能不会融入框架的核心。

    【讨论】:

    • 谢谢,我会试试,让你知道它是如何工作的。
    【解决方案2】:

    状态检查功能

    function test {
        "$@"
        local status=$?
        if [ $status -ne 0 ]; then
            echo "error with $1" >&2
        fi
        return $status
    }
    
    test command1
    test command2
    

    【讨论】:

      【解决方案3】:

      如果您将protractorcucumber-js 一起使用,您可以选择对每个场景(或所有标记为不稳定的场景)进行多次重试:

      ./node_modules/cucumber/bin/cucumber-js --help
      ...
        --retry <NUMBER_OF_RETRIES>     specify the number of times to retry failing test cases (default: 0) (default: 0)
        --retryTagFilter <EXPRESSION>   only retries the features or scenarios with tags matching the expression (repeatable).
                This option requires '--retry' to be specified. (default: "")
      

      不幸的是,如果每个失败的场景都已成功重试,Protractor 仍将返回退出代码 1: https://github.com/protractor-cucumber-framework/protractor-cucumber-framework/issues/176

      作为一种解决方法,在启动 protractor 时,我将以下内容附加到其命令行:

      const directory = 'build';
      ensureDirSync(directory);
      const cucumberSummary = join(directory, 'cucumberSummary.log');
      
      protractorCommandLine += ` --cucumberOpts.format=summary:${cucumberSummary} \
            || grep -P "^(\\d*) scenarios? \\(.*?\\1 passed" ${cucumberSummary} \
            && rm ${cucumberSummary}`;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-08-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多