如何在Jenkins中执行WebDriver测试时获得测试结果?

时间:2012-02-26 09:47:30

标签: playframework jenkins report selenium-webdriver selenium-firefoxdriver

我正在使用Play! WebDrive模块和作业运行正常但是当测试失败时,Jenkins作业显示“所有测试都通过了”。我正在尝试连接测试结果,但我一直遇到麻烦。

我尝试使用Jenkins的SeleniumHQ插件但导致下面显示的错误。我使用Firefox,所以我将测试结果位置设置为{app} / test-result / FirefoxDriver / * .html

Publishing Selenium report...
ERROR: No Test Report Found
Build step 'Publish Selenium Report' changed build result to FAILURE
Finished: FAILURE

所以我猜输出不是Selenium。我试着拉进Play!插件并没有给出任何好的选择。我确实试过了Play!自动测试报告构建后步骤但仅导致显示应用程序日志。

最后,我尝试使用发布测试工具结果报告构建后步骤。这个特别令人沮丧,因为文档非常糟糕,Jenkins没有提供我能找到的任何调试/故障排除信息。

Custom Tool Pattern: {app}/test-result/FirefoxDriver/*.html
Custom stylesheet: scripts/webdrive2junit.xsl

我设置的XSL在下面,然后我一直得到的错误低于那个。有人从webdrive获得测试结果:测试Jenkins工作吗?

<?xml version="1.0" encoding="UTF-8"?>
<!--
 - Hopefully we won't use this for long.  I put it together to get some information
 - out of the webdrive:test results while I look for a better solution.
 -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="child::body">
    <xsl:variable name="test" select="normalize-space(descendant::div/h1)"/>
    <testsuite>
      <xsl:attribute name="name">
        <xsl:value-of select="$test"/>
      </xsl:attribute>
      <testcase>
        <xsl:attribute name="classname">
          <xsl:value-of select="$test"/>
        </xsl:attribute>
        <xsl:attribute name="name">
          <xsl:value-of select="descendant::div/div/table/thead/tr/th"/>
        </xsl:attribute>
        <xsl:if test="descendant::tr[@class='  status_failed']">
          <error />
        </xsl:if>
      </testcase>
    </testsuite>   
  </xsl:template>
</xsl:stylesheet>

这是我在作业日志中收到的错误。

[xUnit] [INFO] - [Custom Tool] - 1 test report file(s) were found with the pattern 'src/test-result/FirefoxDriver/*.html' relative to '/opt/ci/hudson/workspace/enterprise_another-play-test' for the testing framework 'Custom Tool'.
[xUnit] [ERROR] - Conversion error Error to convert - A file not found
ERROR: Publisher org.jenkinsci.plugins.xunit.XUnitPublisher aborted due to exception
hudson.util.IOException2: remote file operation failed: /opt/ci/hudson/workspace/enterprise_another-play-test at hudson.remoting.Channel@34b246:build-trunk-2
...
Caused by: com.thalesgroup.hudson.plugins.xunit.exception.XUnitException: Conversion error Error to convert - A file not found
    at com.thalesgroup.hudson.plugins.xunit.service.XUnitConversionService.convert(XUnitConversionService.java:89)
    at com.thalesgroup.hudson.plugins.xunit.service.XUnitTransformer.invoke(XUnitTransformer.java:135)
    ... 11 more
Caused by: com.thalesgroup.dtkit.util.converter.ConversionException: Error to convert - A file not found
    at com.thalesgroup.dtkit.util.converter.ConversionService.convert(ConversionService.java:369)
    at com.thalesgroup.dtkit.util.converter.ConversionService.convert(ConversionService.java:177)
    at com.thalesgroup.dtkit.util.converter.ConversionService.convert(ConversionService.java:114)
    at com.thalesgroup.dtkit.metrics.model.InputMetricXSL.convert(InputMetricXSL.java:196)
    at com.thalesgroup.dtkit.metrics.model.InputMetricXSL.convert(InputMetricXSL.java:202)
    at com.thalesgroup.hudson.plugins.xunit.service.XUnitConversionService.convertCustomInputMetric(XUnitConversionService.java:104)
    at com.thalesgroup.hudson.plugins.xunit.service.XUnitConversionService.convert(XUnitConversionService.java:78)
    ... 12 more
Caused by: org.xml.sax.SAXParseException: The element type "meta" must be terminated by the matching end-tag "</meta>".
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    at com.thalesgroup.dtkit.util.converter.ConversionService.convert(ConversionService.java:324)
    ... 18 more
Finished: FAILURE

1 个答案:

答案 0 :(得分:0)

我目前的解决方法如下。任何改进将不胜感激。由于Play插件对我来说效果不佳(因为出现了webdrive模块),我的构建步骤是bash脚本。

# work-around for the XUnit Plugin trouble; feel free to Tidy up
find src/test-result/FirefoxDriver -name "*.html" -print0 | xargs -r0 -n 1 bash -c '
  testname=$(basename ${0%.html.*.html});
  xsltproc --html -o src/test-result/FirefoxDriver/TEST-$testname.xml scripts/webdrive2junit.xsl $0
'

我查看了Jenkins的XUnit插件的代码(我相信它是发布测试工具结果报告后构建步骤的背后),我意识到它没有按照我的想法进行。