Search code examples
groovyautomated-testsgeb

GEB: Disable implicit assertions in waitFor block


I have a waitFor{} block with several lines inside:

waitFor(timeOutSeconds) {
    jobRow.clickUpdate()
    processDialog.waitIfShown()
    jobRow.statusCell.text() == status.value
}

According to The Book of GEB:

Any calls to refreshWaitFor() method have implicit assertions added to each expression in the bloc passed to it just like for waitFor() method calls.

The problem is that processDialog.waitIfShown() can return false, and this is actually okay if the progress bar was not displayed.

I need the only last row to be verified for groovy truth, so now I'm writing processDialog.waitIfShown() || true to skip this expression verification. This works but looks odd.

Is there any flag or option to turn off implicit assertions in waiting blocks?


Solution

  • If you would like to disable implicit assertions for a specific waitFor() call then no, that's currently not supported out of the box. There is a number of workarounds, though:

    • implicit assertions can be disabled globally if you remove org.gebish:geb-implicit-assertions artifact from the compile classpath - it's a transitive dependency of geb-core and excluding transitive dependencies is relatively easy in all major build systems
    • implicit assertions are not applied on calls to void methods - if you wrap processDialog.waitIfShown() into a method having void as the return type then calls to that method will not be asserted
    • implicit assertions are only applied to waitFor() calls if closure literals are passed to them - if you assign your condition closure to a variable and then pass that variable to the waitFor() call then no statements in that closure will be implicitly asserted

    If you believe that the above options/workarounds are insufficient then please feel free to raise an issue in the tracker.