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

时间:2013-05-28 12:50:21

标签: selenium ant jenkins

我已经设置了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将在遇到的第一次失败时终止构建。一旦构建完成后是否可以检查失败,然后将其标记为失败?

2 个答案:

答案 0 :(得分:2)

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

进一步阅读:

答案 1 :(得分:1)

构建失败时,会创建testng-failed.xml。您可以在workspace / Test Report / BuildDirectory /

中找到此xml文件

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