Forum Discussion

rohitvarsha12's avatar
8 years ago

Getting test step status at end of iteration



In My Test Suite I have 1 Test case. This test case has 3 Steps.and I have data loop for these three steps(So Total Steps are now 5 One for Test data one for Data loop and 3 original test cases). At the end of each iteration I want to check which all Test steps got passed/failed and write them to Test properties.


Do anyone know how to accomplish this task?


2 Replies

  • Radford's avatar
    Super Contributor

    You should be able to identify the status of the steps with a Groovy test step and the following code:


    testRunner.getResults().each() { result ->
    	if(result.getStatus().toString() != 'OK' ){
    		log.error('TestStep "' + result.getTestStep().getName() + '" finished with the status ' + result.getStatus().toString())		
    		result.getMessages().each() { message ->
    			log.error('Error message: ' + message) 


    This step can be put, just before you datasource loop, at the moment this just logs the failed status messages, you can do what you need to instead.


    If you are expecting steps to fail and you want to continue execution of your test case, you may need to look at the TestCase options? In particular the two options:


    • Abort on Error
    • Fail Test Case on Error

    And set to suit your needs.

  • Hi,

    It was some time ago you wrote this question but since this seem to be a hot topic I want show my solution.


    Actually, for me it worked by just creating an Event (TestRunListener.afterStep) and then add this code in that event.


     def testStepStatus =  testStepResult.getStatus()         
     def testStepName = context.testCase.getTestStepAt(context.getCurrentStepIndex()).getLabel()
        //check if any test step has FAILED. + " : " + " finished with the status " + testStepStatus + "\n")



    This will give you an output like:

    Wed Jul 04 14:32:24 CEST 2018: INFO: TestStep1:  finished with the status PASS
    Wed Jul 04 14:32:24 CEST 2018: INFO: TestStep2:  finished with the status FAIL

    Wed Jul 04 14:32:24 CEST 2018: INFO: TestStep3:  finished with the status PASS


    Note that his will not be run if you have the flag "Abort test if an error occurs" which is found on the TestCase level. Right-click on test case and select Options.


    Also if you further want to use the test step status you will probably need to use .toString(). Example.

    if(testStepStatus.toString() == "FAIL")

    //do something