使用Windows 7和SOAP5.2.0免费软件。
我还在智能熊社区询问了这个问题,只给我推荐的文章供阅读。这些帖子与这个问题无关。
我有一个REST项目,它有一个测试套件,其中一个测试用例包含两个测试步骤。第一步是用groovy脚本调用第二个测试步骤的groovy步骤。第二个测试步骤是REST请求,它向我们的API服务器发送一个字符串,并收到一个JSON格式的响应。第二个测试步骤有一个脚本断言,用于执行"log.info测试正在运行“,所以我可以看到第二个测试何时运行。
当groovy脚本调用第二个测试步骤时,它会在groovy脚本中读取第二个测试步骤的JSON响应,如下所示:
def response = context.expand('${PingTest#Response}').toString() // read results我也可以用它来获得JSON响应:
def response = testRunner.testCase.getTestStepByName(testStepForPing).getPropertyValue("response") 该项目在通过Soap运行时按预期运行,但当我使用测试运行程序运行项目时,使用上面所示的任何一种方法,从groovy脚本调用获得JSON响应的响应都是空的。当从testrunner运行时,我知道正在调用第二个测试步骤,因为我在脚本日志中看到了log.info结果。
这是DOS日志的一部分,它显示第二个测试步骤正在运行,并且第二个测试步骤运行似乎没有错误。
SoapUI 5.2.0 TestCase Runner
12:09:01,612 INFO [WsdlProject] Loaded project from [file:/C:/LichPublic/_Soap/_EdPeterWorks/DemoPing.xml]
12:09:01,617 INFO [SoapUITestCaseRunner] Running SoapUI tests in project [demo-procurement-api]
12:09:01,619 INFO [SoapUITestCaseRunner] Running Project [demo-procurement-api], runType = SEQUENTIAL
12:09:01,628 INFO [SoapUITestCaseRunner] Running SoapUI testcase [PingTestCase]
12:09:01,633 INFO [SoapUITestCaseRunner] running step [GroovyScriptForPingtest]
12:09:01,932 INFO [WsdlProject] Loaded project from [file:/C:/LichPublic/_Soap/_EdPeterWorks/DemoPing.xml]
12:09:02,110 DEBUG [HttpClientSupport$SoapUIHttpClient] Attempt 1 to execute request
12:09:02,111 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Sending request: GET /SomeLocation/ABC/ping?echoText=PingOne HTTP/1.1
12:09:02,977 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Receiving response: HTTP/1.1 200
12:09:02,982 DEBUG [HttpClientSupport$SoapUIHttpClient] Connection can be kept alive indefinitely
12:09:03,061 INFO [log] **Test Is Run**这是我在DOS命令行中使用的testrunner调用:
“C:\Program Files\SmartBear\SoapUI-5.2.0\bin\testrunner.bat" DemoPing.xml当groovy脚本在测试运行程序中运行时,我使用ProjectFactoryRegistry和WsdlProjectFactory获得项目。如果我在使用testrunner时不能阅读JSON响应的任何建议,我们将不胜感激。
如果需要,我可以提供更多的信息/代码。
谢谢。
发布于 2015-09-25 19:44:09
请试用以下脚本:
import groovy.json.JsonSlurper
//provide the correct rest test step name
def stepName='testStepForPing'
def step = context.testCase.getTestStepByName(stepName)
def response = new String(step.testRequest.messageExchange.response.responseContent)
log.info response
def json = new JsonSlurper().parseText(response)发布于 2015-09-26 21:48:22
谢谢饶!你的建议在我使用时是有效的,如下所示。DOS窗口显示了响应文本:
//将stepName设置为运行测试步骤名称的变量。
def stepName = "PingTest“
//使用stepName获取调用测试步骤的测试步骤(testCase是测试用例名称的字符串变量)。
def step = context.testCase.getTestStepByName(stepName)
//调用测试步骤。
step.run(testRunner,上下文)
//显示结果。
def响应=新的String(step.testRequest.messageExchange.response.responseContent)
log.info响应//此响应在DOS窗口中正确显示
json睡眠器也能工作。在您方便的时候,如果您有任何建议的链接或书籍描述您在这里使用的技术,请让我知道他们。
谢谢。
https://stackoverflow.com/questions/32784152
复制相似问题