当硒测试失败时,使Jenkins构建失败 [英] Making Jenkins build fail when Selenium tests fail

查看:129
本文介绍了当硒测试失败时,使Jenkins构建失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

进一步阅读:

  • http://ant.apache.org/manual/Tasks/junit.html
  • http://ant.apache.org/manual/Tasks/fail.html

这篇关于当硒测试失败时,使Jenkins构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆