Forum Discussion

erki's avatar
erki
Occasional Contributor
12 years ago

looping while teststep passes - fails testcase

I have a scenario where i am polling the database while something i expect happens (because it takes some time for stuff to happen in db).
I am using groovy for looping, something similar to:

def lastResult = testRunner.getResults().last().getStatus().toString()

if( lastResult == 'FAILED' )
{
sleep 5000
testRunner.gotoStepByName('check_email')
}
else
{
log.info 'All cool with emails'
}


I would expect that if the last step succeeded (doesn't care how many tries it takes) the whole case would pass, but i am getting:
TestCase failed [Failing due to failed test step], time taken = 22146

And RunTestCaseLog is showing:
Step 14 [Check Email] FAILED: took 10757 ms
-> check_email - FAILED - 224
-> - [Script Assertion] assert count > 1.toInteger()
| | |
0 | 1
false
-> isOk? - OK - 5001
-> check_email - FAILED - 265
-> isOk? - OK - 5000
-> check_email - OK - 229
-> isOk? - OK - 0
TestCase failed [Failing due to failed test step], time taken = 22146


How can i make the testcase pass.
  • erki's avatar
    erki
    Occasional Contributor
    It is very cool that i tend to figure things out 5 minutes after i have given up and come to the forum for help.
    The TestCase has "fail if it has any errors in any steps" option. doh.
  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    Glad you figured it out. Personally, I would remove the assertion there and give that responsibility to your groovy script.

    Also, the way it works, if you test case was to actually fail, how would you prevent it from being a simulated infinite loop? Do you have any sort of checks or balances to say after xx amount of time passes, we no longer care if the email is sent?

    If you wanted to do that, store a property with the time that it started, check if the property exists (if not set it) and if more than the allotted time has passed (if so fail it all). When the script finds the email, have it remove the property.