Jenkins testng插件显示xml解析错误(内容中不允许解析XML:字符]]>)

时间:2018-06-25 08:56:14

标签: selenium jenkins xml-parsing testng assert

在“发布Testng结果”步骤中,jenkins控制台出现错误

Processing '/var/lib/jenkins/jobs/myseleniumJob/builds/9/testng/testng-results.xml'
Failed to parse XML: characters ]]> are not allowed in content (position: CDSECT seen ...te: # Distinct OrderID] \'COL1\' , [Time.Year] \'COL2\' FROM [ALL]]]]>... @20965:901) 
org.xmlpull.v1.XmlPullParserException: characters ]]> are not allowed in content (position: CDSECT seen ...te: # Distinct OrderID] \'COL1\' , [Time.Year] \'COL2\' FROM [ALL]]]]>... @20965:901) 
    at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1343)
    at org.xmlpull.mxp1.MXParser.nextToken(MXParser.java:1100)
    at hudson.plugins.testng.parser.ResultsParser.parse(ResultsParser.java:154)
    at hudson.plugins.testng.TestNGTestResultBuildAction.loadResults(TestNGTestResultBuildAction.java:120)
    at hudson.plugins.testng.Publisher.perform(Publisher.java:141)
    at org.jenkins_ci.plugins.flexible_publish.builder.FailAtEndBuilder.perform(FailAtEndBuilder.java:104)
    at org.jenkins_ci.plugins.run_condition.BuildStepRunner$2.run(BuildStepRunner.java:110)
    at org.jenkins_ci.plugins.run_condition.BuildStepRunner$Fail.conditionalRun(BuildStepRunner.java:154)
    at org.jenkins_ci.plugins.run_condition.BuildStepRunner.perform(BuildStepRunner.java:105)
    at org.jenkins_ci.plugins.flexible_publish.strategy.FailAtEndExecutionStrategy.perform(FailAtEndExecutionStrategy.java:85)
    at org.jenkins_ci.plugins.flexible_publish.ConditionalPublisher.perform(ConditionalPublisher.java:206)
    at org.jenkins_ci.plugins.flexible_publish.FlexiblePublisher.perform(FlexiblePublisher.java:124)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:782)
    at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:723)
    at hudson.model.Build$BuildExecution.post2(Build.java:185)
    at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:668)
    at hudson.model.Run.execute(Run.java:1763)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:410)

我生成的testng-results.xml的摘录

            <test-method status="FAIL" signature="verifyCustomSet_In_Query()[pri:0, instance:com.test.myTest.Test@7ac3aa7d]" name="verifyCustomSet_In_Query" duration-ms="5336" started-at="2018-06-24T23:00:58Z" depends-on-methods="com.test.myTest.Test.verifyQueries" finished-at="2018-06-24T23:01:03Z">
          <exception class="java.lang.AssertionError">
            <message>
              <![CDATA[Queries didn't match expected [pushdown:SELECT USING OUTER JOIN IIF( STAT ( COUNT, 0, [Categories.CategoryName], SELECT [Categories.CategoryName] FROM [All] WHERE [Categories.CategoryName] = %0 AND [Categories.CategoryName] IN ( SELECT TOP 100 USING OUTER JOIN [Categories.CategoryName] 'COL0' , [OrderDate: Sum: Quantity] 'COL1' FROM [ALL] WHERE ( ( [OrderDate: Sum: Quantity]>5000 ) ) ) ) > 0,'In Value', 'Out Value') 'COL0' , [OrderDate: # Distinct OrderID] 'COL1' , [Time.Year] 'COL2' , [Categories.CategoryName] FROM [ALL]] but found [pushdown:SELECT USING OUTER JOIN IIF( [Categories.CategoryName] IN ( SELECT TOP 100 USING OUTER JOIN [Categories.CategoryName] 'COL0' , [OrderDate: Sum: Quantity] 'COL1' FROM [ALL] WHERE ( ( [OrderDate: Sum: Quantity]>5000 ) ) ),'In Value', 'Out Value') 'COL0' , [OrderDate: # Distinct OrderID] 'COL1' , [Time.Year] 'COL2' FROM [ALL]]]]>
            </message>
            <full-stacktrace>
              <![CDATA[java.lang.AssertionError: Queries didn't match expected [pushdown:SELECT USING OUTER JOIN IIF( STAT ( COUNT, 0, [Categories.CategoryName], SELECT [Categories.CategoryName] FROM [All] WHERE [Categories.CategoryName] = %0 AND [Categories.CategoryName] IN ( SELECT TOP 100 USING OUTER JOIN [Categories.CategoryName] 'COL0' , [OrderDate: Sum: Quantity] 'COL1' FROM [ALL] WHERE ( ( [OrderDate: Sum: Quantity]>5000 ) ) ) ) > 0,'In Value', 'Out Value') 'COL0' , [OrderDate: # Distinct OrderID] 'COL1' , [Time.Year] 'COL2' , [Categories.CategoryName] FROM [ALL]] but found [pushdown:SELECT USING OUTER JOIN IIF( [Categories.CategoryName] IN ( SELECT TOP 100 USING OUTER JOIN [Categories.CategoryName] 'COL0' , [OrderDate: Sum: Quantity] 'COL1' FROM [ALL] WHERE ( ( [OrderDate: Sum: Quantity]>5000 ) ) ),'In Value', 'Out Value') 'COL0' , [OrderDate: # Distinct OrderID] 'COL1' , [Time.Year] 'COL2' FROM [ALL]]
    at org.testng.Assert.fail(Assert.java:93)
    at org.testng.Assert.failNotEquals(Assert.java:512)
    at org.testng.Assert.assertEqualsImpl(Assert.java:134)
    at org.testng.Assert.assertEquals(Assert.java:115)
    at org.testng.Assert.assertEquals(Assert.java:189)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:744)
    at org.testng.TestRunner.run(TestRunner.java:602)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
    at org.testng.SuiteRunner.access$000(SuiteRunner.java:39)
    at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:414)
    at org.testng.internal.thread.ThreadUtil$1.call(ThreadUtil.java:52)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
]]>
            </full-stacktrace>
          </exception> <!-- java.lang.AssertionError -->
          <reporter-output>
          </reporter-output>
        </test-method> <!-- verifyCustomSet_In_Query -->

解析'<message>' /'<full-stacktrace>'标记的内容时失败,该标记包含从test传递的断言消息。 这是否意味着testng希望测试人员通过特定格式的断言消息,并且没有受限字符?

更新

我对此进行了进一步分析,发现“ CDSECT”异常是指上述异常中提到的“ CDATA”部分和“ 20965”行,它指向<message>标记。因此,正如我们所看到的,它是指[CDATA]标签下面的<message>部分

<message>
          <![CDATA[Queries didn't match expected [pushdown:SELECT USING OUTER JOIN IIF( STAT ( COUNT, 0, [Categories.CategoryName], SELECT [Categories.CategoryName] FROM [All] WHERE [Categories.CategoryName] = %0 AND [Categories.CategoryName] IN ( SELECT TOP 100 USING OUTER JOIN [Categories.CategoryName] 'COL0' , [OrderDate: Sum: Quantity] 'COL1' FROM [ALL] WHERE ( ( [OrderDate: Sum: Quantity]>5000 ) ) ) ) > 0,'In Value', 'Out Value') 'COL0' , [OrderDate: # Distinct OrderID] 'COL1' , [Time.Year] 'COL2' , [Categories.CategoryName] FROM [ALL]] but found [pushdown:SELECT USING OUTER JOIN IIF( [Categories.CategoryName] IN ( SELECT TOP 100 USING OUTER JOIN [Categories.CategoryName] 'COL0' , [OrderDate: Sum: Quantity] 'COL1' FROM [ALL] WHERE ( ( [OrderDate: Sum: Quantity]>5000 ) ) ),'In Value', 'Out Value') 'COL0' , [OrderDate: # Distinct OrderID] 'COL1' , [Time.Year] 'COL2' FROM [ALL]]]]>
        </message>

1 个答案:

答案 0 :(得分:0)

我认为这全都与变量名中的破折号(-)有关。例如,让我们尝试在Playground https://groovy-playground.appspot.com/中解析XML

import groovy.util.XmlSlurper
def xml = '''<xml body>'''

def testmethod = new XmlSlurper().parseText(xml)
print testmethod.exception.full-stacktrace

我们收到类似not such property stacktrace的错误。将full-stacktrace更改为full-stacktrace后,打印语句将按预期工作。所以我建议以这种方式解析您的文件:

import groovy.util.XmlSlurper

//replace test-method for testmethod in code
def testmethod = new XmlSlurper().parseText(xml)

print testmethod.exception."full-stacktrace"