Forum Discussion

srishtiK's avatar
Occasional Contributor
9 years ago

Rerun a test step max 3 times in case of 401 and then abort

I have say 10 REST test steps. The first step generates the authorization Id. Any any point in the test run if the service response status is "401:Unauthorized" I need to rerun the first step  , regenerate the Authorization Id and use it to hit the current rest Service again. I need to do it max 3 times. If it still fails i need to abort the test run.

Here is what I tried:

  • Until 3 times for 401 error in the test step assertion I use messageExchange.modelItem.testStep.testCase.getTestStepByName("firstStep").run(context.getTestRunner(),context)  to run the first stepp and regenerate the Auth Id.
  • In the first Step I after generationg the Auth Id I use the same method as above to run the current step again
  • If in the current step assertion the count becomes >3 I throw an error

My issue is even after 3 failures It does not throw the error . It asserts the step and moves on to the next step.


I am totally new to SOAPUI, so no idea about how to go about it. Please help

9 Replies

  • nmrao's avatar
    Champion Level 3
    You can be able to achieve this using groovy script:
    1. step is to get auth id
    2. groovy script which I am proposiing -
    sudo code:
    Initialize a counter to 1 as 1st step already run
    Do below steps If counter is less than or equal to 3, throw error otherwise.
    read first step response.
    if the response has 401, go first step
    if the response has authId, do the required steps and go to next step.
    • srishtiK's avatar
      Occasional Contributor

      I have used the code flow you mentioned , but my problem is when I throw the error after 3rd attempt, nothing happens.The assertion should fail and test run should stop. But ,the assertion is marked OK and  the runner just moves on to the next step