Forum Discussion

PeterKlim's avatar
PeterKlim
Contributor
11 years ago

Looping until desired response

Hi
Need some suggestion , we have an excel sheet with 13000 rows of data and has couple of information which we need to write in the data sheet and also take some input from the data sheet,

There are 2 XML files which need to be sent as an input file to get the final response, the 1st xml gets the input parameter from the data sheet and from the response of the 1st xml file , request id is captured and entered as a request input for the second xml.
There are different status id which means different results , like eg is the status id is 6 that the result is “error” and if the status is 16 “ completed” is the result . So want add a condition that if the status is 11 which means in completed to keep looping through within the same request until we receive as error or completed as the status .

I'm not sure how, but how would I use this code?
if( status == “11” )
testRunner.runTestStepByName( "CheckRequest")

Or this code:
if( context.loopIndex == null )
context.loopIndex = 0
if( ++context.loopIndex < 10 )
testRunner.gotoStepByName( "Name of first TestStep in loop" )

I need to know how to get that part working where we loop though within the same row until the required status is received .
  • NaveenVanapalli's avatar
    NaveenVanapalli
    Occasional Contributor
    Hello Giscard,

    Thanks for your reply.

    We already used the built-in "Condition Goto" test step in the test case in order to continuously loop through the same request XML when the response status is 11, but at the same time we are also looking that this loop should happen for a particular time frame say 3 minutes (or 180 seconds). This way the test case will not be in an infinite loop, if at all the response XML always produces the status value as 11.

    So when the loop time exceeds 3 minutes, if at all we does not get response status value other than 11 then it should jump out of the "Condition goto" test step and process the next row from the "Datasource" test step.

    Could you please provide the way on how to loop the same request XML for a particular time frame which is as mentioned above.

    Regards,
    Naveen
  • Hi Giscard, FYI- I asked Naveen to help out so he posted above. Devi will be posting too. Thanks in advance for your help!
  • Cizo89's avatar
    Cizo89
    Frequent Contributor
    Hi,

    if you're looking for loop in specific time period, try and amend this script to reflect your requirements:

    Integer maxTime = 180
    Integer elapsedTime = 0
    Integer delay = 5
    boolean isStatusChanged = false

    //Loop until the status is still the same or the max. time isn't exceeded
    //Check the status every 5 seconds
    while (elapsedTime < maxTime){
    if (status != "11"){
    isStatusChanged = true
    testRunner.gotoStepByName("Next Step")

    break
    }

    Thread.sleep(delay * 1000)
    elapsedTime += delay
    }

    //If max. time was exceeded and the status is still the same, go to DataSource TestStep in order to generate next row
    if (!isStatusChanged){
    testRunner.gotoStepByName("DataSource")
    }


    Regards,
    Marek