2017-09-25 85 views
1

我正在使用免费的soap-ui版本。 对于基本的添加操作(计算器WSDL),我使用groovy从文本文件提供输入,并且我想保存它的响应。我现在用在soapui中捕获对文本或excel文件的响应

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.Now这是给我完整的XML响应。但我只想获得nodevalue“AddResult”,我想将它保存在一个文件中。

  • 出的4个输入它仅捕获.I想捕捉每个响应最后一个输入的响应。
  • 回答

    0

    对于你的问题1 /这里是一个代码片段来检索groovy xmlNode。
    context.expand('${Add - Request 1#Response#//*AddResult/text()}')
    如果您的响应中有许多名为AddResult的字段,则需要填写完整路径给您的节点。

    对于你的问题2,对不起,我不明白。你说只有最后一个答案是写在你的文件上的?也许这是由于您的write命令会删除文件的内容。相反,你可以使用:inputFileResponse.append("Your response text" + System.getProperty("line.separator"))

    +0

    1)高清响应= context.expand( '$ {添加 - 请求1#回应#// * AddResult /文()}') inputFileResponse.append(响应),我试了一下像这样,但它没有捕获任何东西。 – shiv

    +0

    2)Thankyou,它解决了,但有一个问题,我已经使用** if(nextLine!= null)来循环(因为它是逐行读取文本文件中的数据)**,由于它是**不写最后的回应**,所以我应该写哪个条件,以便它捕获最后的回应。 – shiv