Forum Discussion
It seems intuitive that the teardown script is intended to do cleanup work for the test case or test suite after it executes. Have you tried this code in other scripts - like a requestFilter.afterRequest event handler or a groovy step? Maybe by the time teardown occurs a rerun of the test might have unpredictable results.
I think of scripts running in this order
1. Test Suite (setup script if it exists )
2. requestFilter.filterRequest (if the event handler exists)
3. Test Case (setup script if it exists)
4. Groovy Step (groovy script if it exists)
5. requestFilter.AfterRequst (if the event handler exists)
6.. Test Case closure (Assertion Script -if it exists)
7.. Test Case (teardown script if it exists)
8. Test Suite (teardown script if it exists)
Of course there are other event handler scripts but I normally work with the request filter events.
I have been able to use the afterRequest and access the response and rerun a request.
Bill
- richie7 years agoCommunity HeroBill_In_Irvine
thats a great explanation.....might be obvious to some people but thats laid it out for me quite nicely!
cheers,
richie - chanukya7 years agoOccasional Contributor
Hi,
Thanks for your response.
Could you please provide me a sample code that would allow to rerun a test from teardown script.
- Bill_In_Irvine7 years agoContributor
I will look into it.
Bill
- Bill_In_Irvine7 years agoContributor
I have only been able to rerun a request - you know, a request test step, but not as a test case. A test case can be made up of many test steps, several of which can be requests.
In your code, the "FAIL" should be "FAILED" right? But by the time teardown happens the status will likely be "FINISHED"
As a long shot, if you use a command line script and you can figure how to output the result from testrunner, then your script can repeat the call to testrunner. So you'd run it out of a shell rather than from within the ReadyAPI IDE.
I loaded the REST Sample Project in my ReadyAPI 2.2.0 and I added my own groovy script after the test step "Submit Account Details." There is an earlier test step "View Form." Suppose you have a similar test case. Maybe you'd have a Groovy script to check the status of all request steps.
def responseHeaders = testRunner.getTestCase().getTestStepByName("Submit Account Details").testRequest.response.getResponseHeaders() int retryAttempts = 3 log.info "here 0" //while (retryAttempts > 1) { while ((retryAttempts > 1) && (['HTTP/1.1 200 OK'] != responseHeaders['#status#'])) { retryAttempts = retryAttempts-1 log.info "decrement retry attempts-" + retryAttempts testRunner.runTestStepByName(testRunner.getTestCase().getTestStepByName("Submit Account Details").toString())
// edit May 29 (update responseHeadersresponseHeaders = testRunner.getTestCase().getTestStepByName("Submit Account Details").testRequest.response.getResponseHeaders()
log.info "just ran" } log.info "here 1"
Like the above script can follow "Submit Account Details" request and repeat it if necessary.
I guess since I want to rerun a step using groovy if it failed, I should not use the request step assertion. Instead I would allow the request to run as many times to the limit you want and then have your own assertion script following the groovy script.
You can add an assertion script and check messageExchange.responseHeaders for the #status" to equate to HTTP /1.1 200 OK in an assert statement.
def responseHeaders = messageExchange.getResponseHeaders() log.info "here 0" //while (retryAttempts > 1) { assert ['HTTP/1.1 200 OK'] == responseHeaders['#status#'] log.info "here 1"
attached is an image of my modified REST Sample Project shown in ReadyAPI with the above two scripts added inside the "account creation TestCase"
In summary, I have not been able to give you a way to run a test case in its entirety if it fails. However I used the above scripts to rerun a request step at the test step level.
Bill
Related Content
- 11 years ago
- 6 years ago
- 7 years ago
Recent Discussions
- 21 hours ago