Forum Discussion

Vivek_Malhotra's avatar
Vivek_Malhotra
Occasional Contributor
8 years ago

Repeat a Test Step until you get desired response and then move to next step.

Hi,

I have a requirement where I am querying using a GET Request or say a DB select.

 

This is async service which returns me a state say "in-progress" . Then I added a step called delay with 2 seconds delay and checking the status again as it should be "success" or "fail". However this is not good approach and fails sometimes on different servers.


I am looking for some solution how I can do this?

 

I tried few stuff with Groovy and Data Source Loops but still don't know which is the best approach. Also, for how long shall I loop. It might happen that there is some deadlock on DB Level and this might loop for ever. Shall I have some limit also say 5 seconds or something.

 

I have attached structure of my project. I need to re-run the step called "Verify Payment Status in DB" until status is success and then move to other steps.

Any help will be much appreciated.

 

Thanks,

Vivek

 

  • nmrao's avatar
    nmrao
    8 years ago

     

    def response = context.expand( '${TestStep_101#Response}')
    def holder = new com.eviware.soapui.support.XmlHolder(response)
    if (holder) {
       def isRetry = true
       while(isRetry) {
            def state = holder.getNodeValue('//*:payments/*:payment-state')
            log.info "value of state in the response is ${state}"
            if (state == 'success') {
                log.info "Since the value is success, setting value of isRetry to false"
                isRetry = false
            } else {
               log.info "Retring as state is not success"
               testRunner.runTestStepByName('TestStep_101')
            }
       }
    }

     

    Please check if the above script helps.

     

  • You have to check with your product owner to identify what is the accepted SLA for updating this information in DB. If it's not updated in that much time, your test should ideally report as failed.

     

    Even the deadlock or anything of that sort is again applicable only if your DBAs set it up in that manner. I would check once immediately, then check again at the SLA if this SLA fails, still continue the test execution and check once more after one more time after 2 times the SLA is passed.

     

    If it still fails, it's some one else's job to fix the problem( unless you're the developer :smileyhappy: ).

     

    On a separate note: If you want to repeat this step multiple times, it might be a better idea to loop this test step execution in a Groovy Script test step. Below is a psuedo code which you might want to adjust based on your need.

     

    while ( counter < maxCounter && ['pass','fail'].contains(status) == false ){

        testRunner.runTestStepByName('YOUR_TEST_STEP_NAME')

        // Write some xmlHolder or JsonSlurper code to get value for 'status' variable from service response here

        maxCounter ++

    }

     

    Cheers-

    Gilu Gopi

    • Vivek_Malhotra's avatar
      Vivek_Malhotra
      Occasional Contributor

      Thanks gilugopi for you reply.

       

      I tried belwo loop to repeat "TestStep_101" in my tests until its status is success but it goes to indefinite loop. How to make this come out of the loop as soon as the responseAsXml contains success.

       

      def responseAsXml = context.expand( '${TestStep_101#ResponseAsXml#declare ns1:payments[1]/ns1:payment-state[1]}' )

      while (['success'].contains(responseAsXml) == false ){
      testRunner.runTestStepByName('TestStep_101')
      }

       

      Cheers.

      Vivek

      • nmrao's avatar
        nmrao
        Champion Level 3

         

        def response = context.expand( '${TestStep_101#Response}')
        def holder = new com.eviware.soapui.support.XmlHolder(response)
        if (holder) {
           def isRetry = true
           while(isRetry) {
                def state = holder.getNodeValue('//*:payments/*:payment-state')
                log.info "value of state in the response is ${state}"
                if (state == 'success') {
                    log.info "Since the value is success, setting value of isRetry to false"
                    isRetry = false
                } else {
                   log.info "Retring as state is not success"
                   testRunner.runTestStepByName('TestStep_101')
                }
           }
        }

         

        Please check if the above script helps.