Forum Discussion

SoapQA's avatar
SoapQA
New Contributor
9 years ago
Solved

Json response in groovy script returns nothing when using testrunner.bat DOS command.

Using Windows 7 with Soap 5.2.0 freeware (open source).

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 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 it reads the second test's Json results like this:

 

testStepToUse.run(testRunner, context) // run Rest get test
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")

 

I use this to get at the project in the groovy script so I can run through testrunner.bat or through the Soap UI:

 

def workspace = testRunner.testCase.testSuite.project.workspace
def mainProj = (workspace==null) ?
ProjectFactoryRegistry.getProjectFactory(WsdlProjectFactory.WSDL_TYPE).createNew("C:\\LichPublic\\_Soap\\_EdPeterWorks\\DemoPing.xml") :
workspace.getProjectByName(projectName)
if(!mainProj.open && workspace!=null)
{workspace.openProject(testProject)}

 

The test works fine when run through the Soap UI but when I run with test runner the response from the call that gets the Json response returns nothing (using either of the two methods shown above). I know the test is being called from the groovy script and running because I see the log.info result in the DOS window log shown below:

 

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 [mobile-procurement-api]
12:09:01,619 INFO [SoapUITestCaseRunner] Running Project [mobile-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 /mobility/v1/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 in DOS:
C:\Program Files\SmartBear\SoapUI-5.2.0\bin\testrunner.bat" DemoPing.xml

 

Plese help. If this is a matter of using the Pro version, that's fine. We are finding Groovy scripting very versatile and powerful with SoapUI testing.

 

Thanks.

  • I found the solution for this in Stack Overfloe - thanks to RAO. The suggested links weren't related to this problem.

     

    When running through DOS, I did this in the groovy script per RAO's suggestion.

     

    // setup stepName as variable for name of test step to run.
    def stepName = "PingTest"
    // use stepName to get the test step for calling the test step (testCase is a string variable of the test case name).
    def step = context.testCase.getTestStepByName(stepName)
    // call the test step.
    step.run(testRunner, context)
    // show the results.
    def response = new String(step.testRequest.messageExchange.response.responseContent)
    log.info response // this response shows correctly in the DOS window

     

     

1 Reply

  • SoapQA's avatar
    SoapQA
    New Contributor

    I found the solution for this in Stack Overfloe - thanks to RAO. The suggested links weren't related to this problem.

     

    When running through DOS, I did this in the groovy script per RAO's suggestion.

     

    // setup stepName as variable for name of test step to run.
    def stepName = "PingTest"
    // use stepName to get the test step for calling the test step (testCase is a string variable of the test case name).
    def step = context.testCase.getTestStepByName(stepName)
    // call the test step.
    step.run(testRunner, context)
    // show the results.
    def response = new String(step.testRequest.messageExchange.response.responseContent)
    log.info response // this response shows correctly in the DOS window