Groovy script to run a Teststep doesn't fail when the test Step fails
Instead of copying and pasting test steps that I am using over and over in other test cases i decided to use a grovvy step to call the test step. When one of the assertions fail on the step the grovvy step is not failed but instead the test continues onto the next step. I am at a loss for how to get the step to fail when the test step called has a failure in one or more of the assertions. Any help would be appreciated.
Here is the groovy step I am using:
//Generate Authentication Token
// Run the test step
def auth = testRunner.testCase.testSuite.getTestCaseByName("followup_email - Valid English First").getTestStepByName("Generate Auth Token")
//Execute Test Step
auth.run(testRunner, context)
//CHECK FAILED COMMUNICATIONS
// Run the test step
def tStep = testRunner.testCase.testSuite.getTestCaseByName("followup_email - to: Field is Missing").getTestStepByName("Check for Failed Communications")
//Execute Test Step
tStep.run(testRunner, context)
//Results
log.info(tStep.getAssertionStatus())
log.info(tStep.getAssertableContentAsXml())
When log.info(tStep.getAssertionStatus()) comes back FAIL the groovy step is not failed
All you need is just a line in order to check if the particular test step us passed or not.
Rremove every thing after line 10 of your script and add below line.
Assuming that the expected result is pass.
assert tStep.run(testRunner, context).status.toString() in ['OK', 'UNKNOWN'], ' Test step status does not match with the expected value'
In case you are expecting tStep to be failed, the use below assertion
assert tStep.run(testRunner, context).status.toString() == 'FAILED', 'Test step status does not match the expected result'