1
我有一个测试用例,我想在其中放置断言。断言带有失败原因的SoapUI测试用例
我需要提供断言失败的原因。
我从XML格式的输出是如下:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server</faultcode>
<faultstring>XYZ-001: input is wrong</faultstring>
<detail>
<con:fault xmlns:con="http://www.bea.com/wli/sb/context">
<con:errorCode>XYZ-001</con:errorCode>
<con:reason>input is wrong</con:reason>
<con:location>
<con:node>PipelinePairNode1</con:node>
<con:pipeline>PipelinePairNode1_response</con:pipeline>
<con:stage>stage1</con:stage>
<con:path>response-pipeline</con:path>
</con:location>
</con:fault>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
我期望的结果应该是XML的faultstring节点。
为此,我已经使用此代码的XPath断言尝试:
declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';
declare namespace con='http://www.bea.com/wli/sb/context';
boolean('/soapenv:Envelope/soapenv:Body/soapenv:Fault/')
,我把预期输出正确的。 生成JUnit的报告,这是给一些其他的原因后:
Cancelling due to failed test step
<h3><b>Failure Failed</b></h3><pre>[XPath Match] XPathContains comparison failed for path [declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';
declare namespace con='http://www.bea.com/wli/sb/context';
boolean('/soapenv:Envelope/soapenv:Body/soapenv:Fault/')], expecting [false], actual was [true]
</pre><hr/>
然后我用下面的脚本的Groovy着手:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def requsetHolder = groovyUtils.getXmlHolder(messageExchange.requestContent)
def responseHolder = groovyUtils.getXmlHolder(messageExchange.responseContent)
def refNum = responseHolder.getNodeValue("soapenv:Envelope/soapenv:Body/soapenv:Fault/")
def testrunner = context.getTestRunner();
if (refNum != null){
testrunner.fail("soapenv:Envelope/soapenv:Body/soapenv:Fault/faultstring")
}
,但没有运气这一次也。 junit的失败原因是:
Cancelling due to failed test step
<h3><b>Failure Failed</b></h3><pre>[Script Assertion] net.sf.saxon.trans.XPathException: XPath syntax error at char 46 on line 2 in {...pe/soapenv:Body/soapenv:Fau...}:
Unexpected token "<eof>" in path expression
</pre><hr/>
那么有没有什么办法的,我可以在任何常规或XPath使用断言产生在JUnit输出我的自定义原因。
看起来你是从你的描述中在'Xpath Assertion'中添加'expectcting [false]'而不是'true'? – Rao
不,测试用例失败的原因应该是xml故障标记中提及的原因。但是这里的原因是不同的。有没有什么办法可以通过使用xpath或groovy来声明自定义错误信息。 – Sarvesh
嗯,不清楚。你想用例子添加更多的细节吗? – Rao