Forum Discussion

smartTest's avatar
smartTest
Contributor
14 years ago

Groovy Script when Response Contains 'X' GoTo 'Step Y'

A colleague has asked me a question about something he is trying to do in SoapUI to make his Load testing easier. He is looking for a Groovy script that will do something like the below:

If... the preceeding response step
Contains String...... HTTP response
Then
GoTo the preceeding resopnse step and try again
To a maximum of 'X' times

I'm not bad at editing scripts, but have no idea where to start with writing this one. Has anyone had to do something similar at any time and do you have a script I would use?

I'm going to set a challenge for our developers, but wondered if anyone had come across this one before..

thanks in advance
  • smartTest wrote:
    If... the preceeding response step
    Contains String...... HTTP response
    Then

    timesRetried = 0
    previousResponse = testRunner.testCase.getTestStepByName( 'Name Of Preceeding TestStep' ).testRequest.response.contentAsString
    if( previousResponse.contains('HTTP response') )
    {

    smartTest wrote:
    GoTo the preceeding resopnse step and try again, To a maximum of 'X' times

        if ( timesRetried++ <= x )
    testRunner.gotoStepByName( 'Name Of Preceeding TestStep' )
    }



    Something along those lines. Note that the code is not actually using the logical preceeding TestStep, but a hardcoded name of a TestStep. I left this out for simplicity.

    When I write code like this, I find the soapUI API very useful.

    Hope this gets you in the right direction!

    Henrik
    SmartBear Software
  • Henrik

    That seems to work very well, the timesRetried doesn't seem to stop at the set maximum but I can get someone to look at that later. Thanks for the link to the API as well - unfortunately I'm no good at coding so wouldn't know where to start and our developers were too busy to look into this for me, but I will pass on the link to them for the future.

    thanks again
    Diana