I've got a SoapUI project set up: testcase1: request 1 testcase2: request 2 afterRequest script: check http status, if 401 then run testcase 2 When I run testcase1, the re...
This is how I done it and it seemed to work... The following is my project setup:
You can see that I have a groovy script at the end of TestCase_1. This will check whether the response has a 401 status code and if so it will trigger the execution of TestCase_2:
// Get status code header
def statusCodeHeader = context.testCase.testSteps["Request_1"].testRequest.response.responseHeaders["#status#"]
// Extract only the status code
def statusCode = (statusCodeHeader =~ "[1-5]\\d\\d")[0]
// If the status code is 401 then execute TestCase_2
if (statusCode.equals("401")) {
log.info "yes"
def testSuite = context.getTestCase().getTestSuite()
def refreshTestCase = testSuite.getTestCaseByName("TestCase_2")
refreshTestCase.run(null, false)
}