WithWindow() and power asserts

123 views
Skip to first unread message

Bob Brown

unread,
Sep 14, 2015, 8:05:51 AM9/14/15
to geb-...@googlegroups.com
I am trying to see if I can get PowerAssert goodness from withWindow.

Currently, if withWindow fails, I see:

condition did not pass in 10.0 seconds
geb.waiting.WaitTimeoutException: condition did not pass in 10.0 seconds
at geb.waiting.Wait.waitFor(Wait.groovy:138)
at geb.waiting.DefaultWaitingSupport.doWaitFor(DefaultWaitingSupport.groovy:51)
at geb.waiting.DefaultWaitingSupport.waitFor(DefaultWaitingSupport.groovy:38)
at geb.Page.waitFor(Page.groovy:506)
at geb.Browser.methodMissing(Browser.groovy:207)
at geb.spock.GebSpec.methodMissing(GebSpec.groovy:56)
at tce.TCEExplosionSpec.explosion: flow: Address Check/Caller Supplied_closure4(TCEExplosionSpec.groovy:42)
at tce.TCEExplosionSpec.explosion: flow: Address Check/Caller Supplied_closure4(TCEExplosionSpec.groovy)
at geb.Browser.withWindow_closure4(Browser.groovy:746)
at groovy.lang.Closure.call(Closure.java:426)
at groovy.lang.Closure.call(Closure.java:442)
at geb.Browser.withWindow(Browser.groovy:740)
at geb.Browser.withWindow(Browser.groovy:721)
at geb.spock.GebSpec.methodMissing(GebSpec.groovy:56)
at tce.GebScriptingWindowTrait$Trait$Helper.withScriptingWindow_closure2(GebScriptingWindowTrait.groovy:15)
at tce.GebScriptingWindowTrait$Trait$Helper.withScriptingWindow_closure2(GebScriptingWindowTrait.groovy)
at tce.GebHelperTrait$Trait$Helper.returnsNull(GebHelperTrait.groovy:6)
at tce.GebScriptingWindowTrait$Trait$Helper.withScriptingWindow(GebScriptingWindowTrait.groovy:14)
at tce.TCEExplosionSpec.explosion: flow: Address Check/Caller Supplied(TCEExplosionSpec.groovy:39)

This is fine as far as it goes, but it would be nicer if I could get the proper power assert style of exception that tells me the tested-for and actual values in play.

Is there any way I can achieve this?

For reference, I have the following:

@Stepwise
class TCEExplosionSpec extends GebReportingSpec implements GebScriptingWindowTrait, GebHelperTrait {
...
def "explosion: flow: Address Check"() {
expect:
withScriptingWindow('XXX') {
$('form').with { f ->
f._eventId_next().click()
}
}
}
...
}

Which uses the helper withScriptingWindow:

trait GebScriptingWindowTrait {
def withScriptingWindow(name, c) {
final cl = { title.startsWith(name) }
cl.delegate = c.delegate
returnsNull {
withWindow(cl, c)
}
}
}

Which uses the helper returnsNull for another bit of syntactic simplification:

trait GebHelperTrait {

def returnsNull(c) {
c() == null
}
}


Bob Brown

unread,
Sep 14, 2015, 8:11:20 AM9/14/15
to geb-...@googlegroups.com
I forgot to say:

I have already tried this:

===
trait GebScriptingWindowTrait {
def withScriptingWindow(name, c) {
final cl = { title.startsWith(name) }
cl.delegate = c.delegate
final x = {
assert title.startsWith(name)
withWindow(cl, c)
}
x.delegate = c.delegate
returnsNull x
}
}

===

Which gets close, but no cigar:

===
assert title.startsWith(name)
| |
false TCE: Address Check
Assertion failed:

assert title.startsWith(name)
| |
false TCE: Address Check

at tce.GebScriptingWindowTrait$Trait$Helper.withScriptingWindow_closure2(GebScriptingWindowTrait.groovy:15)
at tce.GebScriptingWindowTrait$Trait$Helper.withScriptingWindow_closure2(GebScriptingWindowTrait.groovy)
at tce.GebHelperTrait$Trait$Helper.returnsNull(GebHelperTrait.groovy:6)
at tce.GebScriptingWindowTrait$Trait$Helper.withScriptingWindow(GebScriptingWindowTrait.groovy:19)
at tce.TCEExplosionSpec.explosion: flow: Address Check/Caller Supplied(TCEExplosionSpec.groovy:39)

===

Cheers,

BOB
>--
>You received this message because you are subscribed to the Google Groups "Geb User Mailing List" group.
>To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+u...@googlegroups.com.
>To post to this group, send email to geb-...@googlegroups.com.
>To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/50A09734-38D7-400E-BB06-AAF6ED17BF86%40transentia.com.au.
>For more options, visit https://groups.google.com/d/optout.


Marcin Erdmann

unread,
Sep 15, 2015, 4:32:03 AM9/15/15
to geb-...@googlegroups.com
1. Which Geb version are you on?
2. I don't see any waitFor calls in the snippets you pasted so it's hard to follow and I don't understand why you would get a WaitTimeoutException - I think you're running a different spec (tce.TCEExplosionSpec.explosion: flow: Address Check/Caller Supplied_closure4(TCEExplosionSpec.groovy:42)) to the one you pasted code for.
3. You cannot assert in the condition passed to the withWindow() because it goes over all opened windows to find the one you want to switch to so it cannot fail but it has to return null if the given window is not the one you're after. And anyway, I don't think that your timeout has anything to do with switching windows, if it was then you'd get a NoSuchWindowException and not a WaitTimeoutException.

Reply all
Reply to author
Forward
0 new messages