Forum Discussion

Alejandro21's avatar
Alejandro21
Occasional Contributor
12 years ago

[Res] reading response length from load test

Hi all,
As part of my test case, I have a groovy script test step in which I read some info about the test case and then store it in a csv file. One of the things I read is the response length to a soap request, using the following

length=testRunner.testCase.testSteps["CheckAvailabilityv2 - Request 1"].testRequest.response.rawResponseData.length


When I execute the test case, I have no problems with this script and can read the response length. However, when create a test load based on this test case, I receive the following error for the groovy script test step

java.lang.NullPointerException: Cannot get property 'length' on null object java.lang.NullPointerException: Cannot get property 'length' on null object

Of course, I previously validated that the response exits, actually I have no problems within the load test to read some parameters from the response, like the following

time=testRunner.testCase.testSteps["CheckAvailabilityv2 - Request 1"].testRequest.response.timeTaken 


Does anybody have an idea of why this behavior while accessing the response length inside a load test? I do need to read the response length, so anybody has a suggestion of another way of doing this that might work with the load test?

Another thing I have noticed is that the TearDown script I have for the test case is not being executed during the load test, is that the expected behavior?

Thanks!!!

Alejandro

6 Replies

  • Hi Alejandro,

    Teardown script will run just once after the load test ends.
    Also for loadtest response length, you will have to use the API call for getContentLength,
    Try this,
    testRunner.testCase.testSteps["Request name"].testRequest.getResponse().getContentLength()

    So here are the API calls,
    http://www.soapui.org/apidocs/com/eviwa ... ponse.html
    http://www.soapui.org/apidocs/com/eviwa ... entLength()

    If you want teardown script to be executed for each run please add it in the load test Groovy script testStep. May be as last step in the load test.

    Thanks,
    Jeshtha
  • Alejandro21's avatar
    Alejandro21
    Occasional Contributor
    Hi Jestha,

    I tried what you suggested and it's working now. One question, I noticed that the value returned by

    testRunner.testCase.testSteps["Request name"].testRequest.getResponse().getContentLength()


    is different from the one returned by

    testRunner.testCase.testSteps["Request name"].testRequest.response.rawResponseData.length


    could you please explain me the difference?

    Regarding moving the teardown script to the groovy script teststep, I have one question. I use the teardown script to read the status of a certain test step using someting like this

    for( r in testRunner.results )
    {
    //log.info "TestStep [" + r.testStep.name + "] finished with status " + r.status
    if(r.testStep.name=="Request Name")
    status=r.status
    }


    I once read that this was only possible from within the testcase teardown script. Can I access the status of a certain test step from within another test step? If possitive, could you please tell me how to do it?

    Thanks!!

    Alejandro
  • Hi,

    The length with raw response data is in byte format whereas the API call returns in long format.


    for( r in testRunner.results )
    {
    //log.info "TestStep [" + r.testStep.name + "] finished with status " + r.status
    if(r.testStep.name=="Request Name")
    status=r.status
    }


    testRunner results are available with reference. Try adding it I havent tried to run in the testcase, but try adding test step at the end and add the script. It also depends on the sequence.

    Thanks,
    Jeshtha
  • Alejandro21's avatar
    Alejandro21
    Occasional Contributor
    Hi Jeshta,

    it worked. As you suggested I added it at the last teststep. One final question, do you know how can I convert from long format to byte format? I can't manage to convert the API call response to match the raw response data value.

    Thanks!!

    Alejandro
  • Hi,

    Instead of ...getResponse().getContentLength(), try ...getResponse().getContentAsString().getBytes().length

    Regards,

    Giscard
    SmartBear Support