如何使用soapUI

时间:2017-05-17 15:36:40

标签: rest groovy soapui

我正在尝试将测试用例中每个测试步骤的所有请求和响应数据保存到该测试用例自定义属性中。我们在CLI中使用soapUI 5.3.0 Open,并且testRunner报告设置为导出到包含测试属性的Junit报告。我们正在尝试这种方法,因为自定义构建监视系统在查看多个文件时遇到问题,因此我们希望将所有内容都放在一个庞大的丑陋xml文件中(我们并不仅限于下面列出的5个属性)

下面的代码可以更好地处理并完成我正在寻找的内容。还没有通过CLI进行测试,所以我会在可能的时候(很可能是明天)报告

testRunner.results.each{ testStepResult -> testRunner.testCase.setPropertyValue("${testStepResult.testStep.name}_timeStamp","${testStepResult.timeStamp}")}
testRunner.results.each{ testStepResult -> testRunner.testCase.setPropertyValue("${testStepResult.testStep.name}_timeTaken","${testStepResult.timeTaken}")}
testRunner.results.each{ testStepResult -> testRunner.testCase.setPropertyValue("${testStepResult.testStep.name}_status","${testStepResult.status}")}
testRunner.results.each{ testStepResult ->
    def step = "${testStepResult.testStep.name}"
    try{response = new String(testRunner.testCase.getTestStepByName("$step").testRequest.messageExchange.rawResponseData)}catch(Exception e){e.getMessage()}
    try{request = new String(testRunner.testCase.getTestStepByName("$step").testRequest.messageExchange.rawRequestData)}catch(Exception e){e.getMessage()}
    testRunner.testCase.setPropertyValue("${testStepResult.testStep.name}_response",response)
    testRunner.testCase.setPropertyValue("${testStepResult.testStep.name}_request",request)
    request = ""
    response = ""
}

1 个答案:

答案 0 :(得分:0)

这种方法可以同时获取WSDL和REST请求+响应,并通过CLI确认工作

testRunner.results.each{ testStepResult -> testRunner.testCase.setPropertyValue("${testStepResult.testStep.name}_timeStamp","${testStepResult.timeStamp}")}
testRunner.results.each{ testStepResult -> testRunner.testCase.setPropertyValue("${testStepResult.testStep.name}_timeTaken","${testStepResult.timeTaken}")}
testRunner.results.each{ testStepResult -> testRunner.testCase.setPropertyValue("${testStepResult.testStep.name}_status","${testStepResult.status}")}
testRunner.results.each{ testStepResult ->
    def step = "${testStepResult.testStep.name}"
    try{response = new String(testRunner.testCase.getTestStepByName("$step").testRequest.messageExchange.rawResponseData)}catch(Exception e){e.getMessage()}
    try{request = new String(testRunner.testCase.getTestStepByName("$step").testRequest.messageExchange.rawRequestData)}catch(Exception e){e.getMessage()}
    testRunner.testCase.setPropertyValue("${testStepResult.testStep.name}_response",response)
    testRunner.testCase.setPropertyValue("${testStepResult.testStep.name}_request",request)
    request = ""
    response = ""
}

正如您所看到的,我必须将reqests \响应包装到try \ catch中,因为在测试用例中并非所有内容都是REST或WSDL。