Permalink
Browse files

GEB-111 message parameter fot waitFor (to use in case of timeout)

  • Loading branch information...
1 parent 722d29d commit 1d5ff73635d4240d29011892185caf0c12cefc05 @erdi erdi committed Jan 15, 2012
@@ -177,6 +177,12 @@ You'll notice when using `waitFor` that when something like `waitFor { 1 == 2 }`
This way, if the conditional fails the error message is meaningful but the block still passes. This is obviously not very convenient, and this will be addressed in a future version of Geb by using Groovy's compile time transform capability. If you are interested in tracking or helping solve this issue, you can follow the issue [GEB-123](http://jira.codehaus.org/browse/GEB-123).
+### Custom message
+
+If you wish to add a custom message to `WaitTimeoutException` that is being thrown when `waitFor` call times out you can do so by providing a message parameter to the `waitFor` call:
+
+ waitFor (message: 'My custom message') { $("div#result").present }
+
## Alert and Confirm Dialogs
WebDriver currently [does not handle](http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions#Q:_Does_support_Javascript_alerts_and_prompts?) the [`alert()` and `confirm()` dialog windows](http://www.w3schools.com/JS/js_popup.asp). However, we can fake it through some Javascript magic as [discussed on the WebDriver issue for this](http://code.google.com/p/selenium/issues/detail?id=27#c17). Geb implements a workaround based on this solution for you. Note that this feature relies on making changes to the browser's `window` DOM object so may not work on all browsers on all platforms. At the time when WebDriver adds support for this functionality the underlying implementation of the following methods will change to use that which will presumably be more robust. Geb adds this functionality through the [`AlertAndConfirmSupport`](api/geb-core/geb/js/AlertAndConfirmSupport.html) class that is mixed into
@@ -331,4 +337,4 @@ The return value of methods called on the `jquery` property depends on what the
### Why?
-This functionality was developed to make triggering mouse related events easier. Some applications are very sensitive to mouse events and triggering these events in an automated environment is a challenge. jQuery provides a good API for faking these events which makes for a good solution.
+This functionality was developed to make triggering mouse related events easier. Some applications are very sensitive to mouse events and triggering these events in an automated environment is a challenge. jQuery provides a good API for faking these events which makes for a good solution.
@@ -42,10 +42,12 @@ This page lists the high level changes between versions of Geb.
* Added support for indexes and ranges in `moduleList()` method
* Form control shortcuts now also work on page and module content
+* Custom timeout message for `waitFor` calls
#### Breaking Changes
* `click()` now instructs the browser to click **only on the first** element the navigator has matched
-* all `click()` method variants return the reciever
+* All `click()` method variants return the reciever
+
### 0.6.2
@@ -43,6 +43,8 @@ class Wait {
* How many seconds to wait before trying something again while waiting.
*/
final Double retryInterval
+
+ String customMessage
Wait(Double timeout = DEFAULT_TIMEOUT, Double retryInterval = DEFAULT_RETRY_INTERVAL) {
@@ -32,6 +32,9 @@ class WaitTimeoutException extends GebException {
private static toMessage(Wait wait, Throwable cause) {
def message = "condition did not pass in $wait.timeout seconds"
+ if (wait.customMessage) {
+ message +=" (${wait.customMessage})"
+ }
if (cause) {
message += " (failed with exception)"
}
@@ -41,7 +41,11 @@ class WaitingSupport {
* @see geb.waiting.Wait#waitFor(groovy.lang.Closure)
*/
def waitFor(String waitPreset, Closure block) {
- doWaitFor(config.getWaitPreset(waitPreset), block)
+ waitFor([:], waitPreset, block)
+ }
+
+ def waitFor(Map params, String waitPreset, Closure block) {
+ doWaitFor(params.message, config.getWaitPreset(waitPreset), block)
}
/**
@@ -55,7 +59,11 @@ class WaitingSupport {
* @see geb.waiting.Wait#waitFor(groovy.lang.Closure)
*/
def waitFor(Closure block) {
- doWaitFor(config.defaultWait, block)
+ waitFor([:], block)
+ }
+
+ def waitFor(Map params, Closure block) {
+ doWaitFor(params.message, config.defaultWait, block)
}
/**
@@ -69,7 +77,11 @@ class WaitingSupport {
* @see geb.waiting.Wait#waitFor(groovy.lang.Closure)
*/
def waitFor(Double timeout, Closure block) {
- doWaitFor(config.getWait(timeout), block)
+ waitFor([:], timeout, block)
+ }
+
+ def waitFor(Map params, Double timeout, Closure block) {
+ doWaitFor(params.message, config.getWait(timeout), block)
}
/**
@@ -84,10 +96,15 @@ class WaitingSupport {
* @see geb.waiting.Wait#waitFor(groovy.lang.Closure)
*/
def waitFor(Double timeout, Double interval, Closure block) {
- doWaitFor(new Wait(timeout, interval), block)
+ waitFor([:], timeout, interval, block)
+ }
+
+ def waitFor(Map params, Double timeout, Double interval, Closure block) {
+ doWaitFor(params.message, new Wait(timeout, interval), block)
}
- private doWaitFor(Wait wait, Closure block) {
+ private doWaitFor(String customMessage, Wait wait, Closure block) {
+ wait.customMessage = customMessage
wait.waitFor(block)
}
@@ -83,6 +83,15 @@ class WaitingSupportSpec extends GebSpecWithServer {
waitFor(1, 10) { $("div").empty }
}
+ def "message argument is appended to the exception message"() {
+ when:
+ waitFor(1, message: 'Some custom message') { false }
+
+ then:
+ WaitTimeoutException e = thrown()
+ e.message =~ 'Some custom message'
+ }
+
def "larger interval than timeout throwing exception"() {
when:
js.showIn(4)

0 comments on commit 1d5ff73

Please sign in to comment.