Forum Discussion

bpistole's avatar
bpistole
Contributor
8 years ago

skip test step using groovy

I have a test where I need to iterate through the response to validate several values.

If the values match I want to goto a "pass" test step but if they fail I want to go to a different "fail" test step.

if (responseCategory != expectedCategory){
   log.info("Test Failed")
   testRunner.gotoStepByName("Test Case  - FAIL")
}
else{
   log.info("Test Passed")
   testRunner.gotoStepByName("Test Case  - PASS")
}

 

The "Test Case - "FAIL" is followed by this script:

testRunner.fail("Result not as expected!")

This is used to abort the test on a fail condition.

After the testRunner.fail there is the "Test Case - "PASS" test step followed by the dataSource loop.

 

However, the test allows follows the fail path regardless of the if/else result.  I can watch the logs and they will log the "Test Passed" yet the "Test Case - "FAIL" test step will run instead of the "Test Case - "PASS" test step.

 

What am I missing here?  My understanding was that the gotoStepByName was programmatically the same as the condition goto test step.  I've used the condition goto test step on other test cases and it worked in this same set up.

 

Thanks,

Billy

  • Nastya_Khovrina's avatar
    Nastya_Khovrina
    SmartBear Alumni (Retired)

    Hi Billy,

     

    I see that you opened a case regarding this issue. It would be great if you can share your project (or a sample project) with us in the case, so we can better understand and test your scenario. Thanks.

  • I ended up getting this working but to be honest, I'm not sure what I did. :)

     

    if (expectedFeature != responseFeature)
    {
    log.info(" " + responseFeature + " != " + expectedFeature)
    log.info(" Fail")
    testRunner.gotoStepByName("TC FAIL")
    }
    else
    {
    log.info(" " + responseFeature + " == " + expectedFeature)
    log.info(" Pass")
    testRunner.gotoStepByName("TC PASS")

    }