我有一個SOAP請求,它具有隨機方法生成的動態值。如何捕獲這些生成的值以記錄?肥皂ui請求內容的動態值
我的SOAP請求:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://www.webserviceX.NET/">
<soap:Header/>
<soap:Body>
<web:ChangeLengthUnit>
<web:LengthValue>${=(int)(Math.random()*9999)}</web:LengthValue>
<web:fromLengthUnit>Inches</web:fromLengthUnit>
<web:toLengthUnit>Centimeters</web:toLengthUnit>
</web:ChangeLengthUnit>
</soap:Body>
</soap:Envelope>
Groovy腳本:
import com.eviware.soapui.support.GroovyUtils;
def prj = testRunner.testCase.testSuite.project.workspace.getProjectByName("Project1")
tCase = prj.testSuites['TestSuite'].testCases['TestCase']
tStep = tCase.getTestStepByName("ChangeLengthUnit")
def stepReq = tStep.getProperty("Request").getValue()
def runner = tStep.run(testRunner, context)
log.info ("runner status ....... : " + runner.hasResponse())
log.info stepReq
for(assertion in tStep.assertionList)
{
log.info "Assertion [" + assertion.label + "] has status [" + assertion.status + "]"
for(e in assertion.errors)
log.info "-> Error [" + e.message + "]"
}
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(stepReq.toString())
log.info holder.getNodeValues("//web:LengthValue").toString()
以上常規腳本如下給人輸出:
Wed Oct 18 14:55:13 SGT 2017:INFO:[${=(int)(Math.random()*9999)}]
LengthValue標籤的實際值= 3 490,如何獲取此值?
請勿使用'workspace',因爲它無法運行side soapui,即如果使用testrunner執行項目,它將失敗。 – Rao