当 Selenium 测试失败时,使 Jenkins 构建失败

当 Selenium 测试失败时,使 Jenkins 构建失败

问题描述:

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

I have setup a Jenkins server for running Selenium tests. The build script is written in Ant (v 1.7.1 on CentOS 6.3) and the tests run on Sauce Labs. I execute the build via shell:

ant -buildfile build.xml

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

The problem is when a test fails, Jenkins marks it a success. I can avert this by setting haltonfailure to true, see:

<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 会在遇到第一次失败时终止构建.是否可以在构建完成后检查失败,然后将其标记为失败?

However, this is not ideal because Jenkins will terminate the build on the first failure it encounters. Is it possible to check for failures once a build has completed and then mark it as failed?

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

On the junit task, use the failureproperty attribute. And then call the fail task with an unless attribute.

进一步阅读: