使用Testrunner时,SoapUI Groovy脚本的JSON响应为空 [英] SoapUI Groovy Script’s JSON Responses Is Empty When Using Testrunner

查看:129
本文介绍了使用Testrunner时,SoapUI Groovy脚本的JSON响应为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Windows 7和Soap 5.2.0免费软件。



我在智能熊社区也询问过这个问题,只给出推荐的帖子供读者阅读。这些帖子并没有涉及到这个问题。

我有一个REST项目,它有一个包含两个测试步骤的测试用例的测试套件。第一步是通过一个groovy脚本来调用第二个测试步骤。第二个测试步骤是一个REST GET请求,它向我们的API服务器发送一个字符串,并以JSON格式接收回应。第二个测试步骤有一个脚本断言,它会执行log.info Test Is Run,所以我可以看到第二个测试运行的时间。



当groovy脚本调用第二个测试步骤它读取groovy脚本中的第二个测试步骤的JSON响应,如下所示:

  def response = context.expand( '$ {PingTest#Response}')。toString()//读取结果

我也可以使用这是为了获得JSON响应:
$ b $ pre $ def response = testRunner.testCase.getTestStepByName(testStepForPing).getPropertyValue(response)

项目在运行Soap UI时按预期运行,但是当我使用测试运行器运行项目时,响应从groovy脚本调用获取JSON响应为空,使用上面显示的任一方法。当从testrunner运行时,我知道第二个测试步骤被调用,因为我在脚本日志中看到了log.info结果。



这是DOS日志的一部分,显示第二个测试步骤正在运行,并且第二个测试步骤运行似乎没有错误。

  SoapUI 5.2.0 TestCase Runner 
12:09:01,612 INFO [WsdlProject]从[file:/ C:/LichPublic/_Soap/_EdPeterWorks/DemoPing.xml]加载项目
12:09:01,617 INFO [SoapUITestCaseRunner]运行SoapUI测试在项目中[demo-procurement-api]
12:09:01,619信息[SoapUITestCaseRunner]运行项目[demo-procurement-api],runType = SEQUENTIAL
12:09:01,628信息[SoapUITestCaseRunner]运行SoapUI testcase [PingTestCase]
12:09:01,633 INFO [SoapUITestCaseRunner]运行步骤[GroovyScriptForPingtest]
12:09:01,932信息[WsdlProject]从[file:/ C:/ LichPublic / _Soap / _EdPeterWorks /DemoPing.xml]
12:09:02,110 DEBUG [HttpClientSupport $ SoapUIHttpClient]尝试1执行请求
12:09:02,111 DEBUG [SoapUIMultiThreadedHttpConnectionManager $ SoapUIDefaultClientConnection]发送请求:GET / SomeLocation / ABC / ping?echoText = PingOne HTTP / 1.1
12:09:02,977 DEBUG [SoapUIMultiThreadedHttpConnectionManager $ SoapUIDefaultClientConnection]接收响应:HTTP / 1.1 200
12:09:02,982 DEBUG [HttpClientSupport $ SoapUIHttpClient]连接可以无限期保持活动状态
12:09:03,061 INFO [log] **测试运行**

这是我在DOS命令行中使用的testrunner调用:

 C:\ Program Files \SmartBear\SoapUI-5.2.0\bin\testrunner.batDemoPing.xml 
code>

当groovy脚本通过测试运行器运行时,我使用ProjectFactoryRegistry和WsdlProjectFactory获取项目。任何建议,为什么我不能阅读JSON响应时使用testrunner将不胜感激。

我可以提供更多的信息/代码,如果需要的话。



谢谢。

解决方案

请尝试下面的脚本:

  import groovy.json.JsonSlurper 
//提供正确的休息测试步骤名称
def stepName ='testStepForPing'
def step = context.testCase.getTestStepByName(stepName)
def response = new String(step.testRequest.messageExchange.response.responseContent)
log.info响应
def json = new JsonSlurper()。parseText (回应)


Using Windows 7 with Soap 5.2.0 freeware.

I also asked about this in the Smart Bear community and was only given recommended posts to read. The posts didn’t relate to this problem.

I have a REST project that has one test suite with one test case containing two test steps. The first step is a groovy step with a groovy script that calls the second test step. The second test step is a REST GET request that sends a string to our API server and receives a response back in JSON format. The second test step has a script assertion that does "log.info Test Is Run", so I can see when the second test is run.

When the groovy script calls the second test step it reads the second test step’s JSON response in the groovy script like this:

def response = context.expand('${PingTest#Response}').toString()  // read results

I can also use this for getting JSON response:

def response = testRunner.testCase.getTestStepByName(testStepForPing).getPropertyValue("response") 

The project runs as expected when run through the Soap UI but when I run the project with test runner, the response from the groovy script call to get the JSON response is empty, using either of the methods shown above. When run from testrunner, I know the second test step is being called because I see the log.info result in the script log.

This is part of the DOS log that shows the second test step is running and it seems there are no errors for the second test step run.

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**

This is the testrunner call I use in DOS command line:

"C:\Program Files\SmartBear\SoapUI-5.2.0\bin\testrunner.bat" DemoPing.xml

When the groovy script is run through test runner I get the project using ProjectFactoryRegistry and WsdlProjectFactory. Any advice on why I can’t read JSON response when using testrunner would be appreciated.

I can provide more info/code if needed.

Thanks.

解决方案

Please try the below script:

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)

这篇关于使用Testrunner时,SoapUI Groovy脚本的JSON响应为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆