我正在使用免费的soap-ui版本。 对于基本的添加操作(Calculator WSDL),我使用groovy从文本文件中输入输入,我想保存它的响应。
我使用的Groovy脚本是:
nextLine=context.fileReader.readLine()
def inputFileResponse = new File("D://file.txt")
if(nextLine!=null){
String[] inpData=nextLine.split(",")
testRunner.testCase.testSteps["Properties"].setPropertyValue("num1",inpData[0])
testRunner.testCase.testSteps["Properties"].setPropertyValue("num2",inpData[1])
inputFileResponse.write(context.testCase.testSteps["Add - Request 1"].getProperty("response").value)
testRunner.gotoStep(0)
}
问题区域:
1.现在这给了我完整的xml响应。但我只想得到nodevalue" AddResult"我想把它保存在一个文件中。
答案 0 :(得分:0)
对于你的问题1 /这是一个在groovy中检索xmlNode的片段
context.expand( '${Add - Request 1#Response#//*AddResult/text()}' )
。
如果您的响应中有许多名为AddResult的字段,则需要填充节点的完整路径。
对于你的问题2,抱歉我不太了解。你说只有最后一个回复被写入你的档案?也许是因为你的write
命令会删除你文件的内容。相反,您可以使用:inputFileResponse.append("Your response text" + System.getProperty("line.separator"))