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
Solved! Go to Solution.
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 ).
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
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 ns1ayments[1]/ns1
ayment-state[1]}' )
while (['success'].contains(responseAsXml) == false ){
testRunner.runTestStepByName('TestStep_101')
}
Cheers.
Vivek
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.
This has probably been resolved and moved on from long ago, but this sounds like a perfect use-case for my flow-plugin that contains the Repeat Test Step.
It makes use of testStep status so you can make an assertion that tests for this.
The repeat test step would test it a finite amount of attempts and let the test through when all test steps pass.
Hope it helps!
Hello,
I have tried to use your solution above and having some issues with it.
My code is as follows-
import com.eviware.soapui.support.* import groovy.json.JsonSlurper a = testRunner.testCase.getTestStepByName("TestStepName") responsedata = a.getProperty("Response").getValue(); def jsonSlurper = new JsonSlurper().parseText(responsedata) def retry = true; while (retry) { if (jsonSlurper.items[0].processingStatus == 'DONE' && jsonSlurper.items[1].processingStatus == 'DONE' && jsonSlurper.items[2].processingStatus == 'DONE') { log.info "All Processed, time to run the next test case" retry = false; } else { log.info "Retry again until processed is received" testRunner.runTestStepByName('TestStepName') } }
The problem is that, in my case even when the condition is met, the script goes into an endless loop. Is there something glaring which I have missed.
Thanks in advance for your help.
User | Count |
---|---|
5 | |
3 | |
3 | |
2 | |
1 |
Subject | Author | Latest Post |
---|---|---|