Forum Discussion

HimanshuTayal's avatar
HimanshuTayal
Community Hero
5 years ago
Solved

Wait until request executed successfully

Hi Community Members,

 

I have stuck at a point where i need to pause/wait my groovy steps untill my request get executed successfully.

And i am hitting my request via groovy and then asserting it. I don't want to use hardcore wait like Thread.sleep()

 

Suppose below is my groovy

 

1. Some code

2. testRunner.run

wait(i want to wait untill step 2 gets executed and response gets generated.)

3. some code to verify response

 

I want it dynamic. Thanks in Advance.

 

  • nmrao's avatar
    nmrao
    5 years ago

    HimanshuTayal 

    Not sure why you want to run REST request from a groovy script instead of having a REST Request step. Any specific reason?

     

    If the assertion is added REST Request, are not those executed directly instead of verifying them in Groovy Script?

     

    Any ways, it appears that you do not need to wait or use sleep.

    See if the below snippet of code helps (follow comments)

     

    import static com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus.*
    import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep
    import com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep
    import com.eviware.soapui.impl.wsdl.teststeps.JdbcRequestTestStep
    import com.eviware.soapui.impl.wsdl.teststeps.HttpTestRequestStep
    
    /*
     Your code before run method comes here
    */
    def result = step.run(testRunner, context)
    def isStepRequestType = { model -> [WsdlTestRequestStep, RestTestRequestStep, JdbcRequestTestStep, HttpTestRequestStep].any { model.class == it} }
    switch(result.status) { case FAILED: log.error "${step.name} is executed, but failed" break case [OK, UNKNOWN] : log.info "${step.name} execution is finished successfully" if (isStepRequestType(step)) { def response = result.responseContent assert response, 'Response is null or empty'
    log.debug response //Add other assertions on response as needed - verification part } break //last statement in case default: log.info result.status break }

6 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    " i am hitting my request via groovy" - What kind of request? And sample code that is used?
    • HimanshuTayal's avatar
      HimanshuTayal
      Community Hero

      Hi nmrao ,

       

      My Request is of REST Type and below is the sample code, currently i am using Thread. sleep, but instead i want to wait till my request gets run.

       

      def runStatus = appAssignStep.run(testRunner, context);
      Thread.sleep(4000)//want to replace this with dynamic wait
      verifyResponseValue(appAssignStep.getPropertyValue("Response"))

       

      • nmrao's avatar
        nmrao
        Champion Level 3

        HimanshuTayal 

        Not sure why you want to run REST request from a groovy script instead of having a REST Request step. Any specific reason?

         

        If the assertion is added REST Request, are not those executed directly instead of verifying them in Groovy Script?

         

        Any ways, it appears that you do not need to wait or use sleep.

        See if the below snippet of code helps (follow comments)

         

        import static com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus.*
        import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep
        import com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep
        import com.eviware.soapui.impl.wsdl.teststeps.JdbcRequestTestStep
        import com.eviware.soapui.impl.wsdl.teststeps.HttpTestRequestStep
        
        /*
         Your code before run method comes here
        */
        def result = step.run(testRunner, context)
        def isStepRequestType = { model -> [WsdlTestRequestStep, RestTestRequestStep, JdbcRequestTestStep, HttpTestRequestStep].any { model.class == it} }
        switch(result.status) { case FAILED: log.error "${step.name} is executed, but failed" break case [OK, UNKNOWN] : log.info "${step.name} execution is finished successfully" if (isStepRequestType(step)) { def response = result.responseContent assert response, 'Response is null or empty'
        log.debug response //Add other assertions on response as needed - verification part } break //last statement in case default: log.info result.status break }