Forum Discussion
Hi,
Thanks for your response.
Could you please provide me a sample code that would allow to rerun a test from teardown script.
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 responseHeaders
responseHeaders = 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
- 18 days ago