【问题标题】:Making Jenkins build fail when Selenium tests fail当 Selenium 测试失败时使 Jenkins 构建失败
【发布时间】:2013-05-23 10:53:23
【问题描述】:

我已经设置了一个 Jenkins 服务器来运行 Selenium 测试。构建脚本是用 Ant(CentOS 6.3 上的 v 1.7.1)编写的,测试在 Sauce Labs 上运行。我通过 shell 执行构建:

ant -buildfile build.xml

问题是当测试失败时,Jenkins 将其标记为成功。我可以通过将haltonfailure 设置为true 来避免这种情况,请参阅:

<junit printsummary="yes" fork="false" haltonfailure="yes">
    <classpath refid="run.cp" />
    <formatter type="xml" usefile="true"    />
    <batchtest fork="no" todir="test-output/xml">
        <fileset dir="src/">
            <exclude name="**/*LocatorUtils*.java"/>
            <exclude name="**/*TestBase*.java"/>
            <exclude name="**/*TestUtils*.java"/>
            <exclude name="**/*Config*.properties"/>
        </fileset>
    </batchtest>
</junit>

但是,这并不理想,因为 Jenkins 将在遇到第一次失败时终止构建。是否可以在构建完成后检查失败然后将其标记为失败?

【问题讨论】:

    标签: selenium ant jenkins


    【解决方案1】:

    当构建失败时,会创建 testng-failed.xml。你可以在workspace/Test Report/BuildDirectory/中找到这个xml文件

    这里每次都会创建 BuildDirectory。您可以编写一个 powershell 脚本来检查是否创建了 testng-failed.xml。如果构建成功,则不会创建此文件。

    【讨论】:

      【解决方案2】:

      junit 任务上,使用failureproperty 属性。然后使用unless 属性调用fail 任务。

      进一步阅读:

      【讨论】:

        猜你喜欢
        • 2015-04-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-17
        • 2019-10-17
        • 2016-01-04
        • 2018-04-29
        • 1970-01-01
        相关资源
        最近更新 更多