Skip to content

Commit e56e484

Browse files
committed
fix(geb): system property setting of timeout values
1 parent 79b8708 commit e56e484

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

grails-geb/README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,34 @@ the `container` from within your `ContainerGebSpec` to, for example, call `.copy
135135
An Example of this can be seen in [ContainerSupport#createFileInputSource utility method](./src/testFixtures/groovy/grails/plugin/geb/support/ContainerSupport.groovy).
136136

137137
#### Timeouts
138-
138+
The following system properties exist to configure timeouts:
139+
140+
* `grails.geb.atCheckWaiting.enabled`
141+
* purpose: if `at` checks should wait for the page to be in the expected state (uses configured waiting timeout values)
142+
* type: boolean
143+
* defaults to `false`
144+
* `grails.geb.timeouts.retryInterval`
145+
* purpose: how often to retry waiting operations
146+
* type: Number
147+
* defaults to `0.1` seconds
148+
* `grails.geb.timeouts.waiting`
149+
* purpose: amount of time to wait for waiting operations
150+
* type: Number
151+
* defaults to `5.0` seconds
139152
* `grails.geb.timeouts.implicitlyWait`
140153
* purpose: amount of time the driver should wait when searching for an element if it is not immediately present.
154+
* type: int
141155
* defaults to `0` seconds, which means that if an element is not found, it will immediately return an error.
142156
* Warning: Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times.
143157
Consult the [Geb](https://groovy.apache.org/geb/manual/current/#implicit-assertions-waiting)
144158
and/or [Selenium](https://www.selenium.dev/documentation/webdriver/waits/) documentation for details.
145159
* `grails.geb.timeouts.pageLoad`
146160
* purpose: amount of time to wait for a page load to complete before throwing an error.
161+
* type: int
147162
* defaults to `300` seconds
148163
* `grails.geb.timeouts.script`
149164
* purpose: amount of time to wait for an asynchronous script to finish execution before throwing an error.
165+
* type: int
150166
* defaults to `30` seconds
151167

152168
#### Observability and Tracing

grails-geb/src/testFixtures/groovy/grails/plugin/geb/GrailsGebSettings.groovy

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import groovy.transform.CompileStatic
2525
import groovy.transform.Memoized
2626
import groovy.util.logging.Slf4j
2727

28+
import geb.waiting.Wait
29+
2830
import static org.testcontainers.containers.BrowserWebDriverContainer.VncRecordingMode
2931
import static org.testcontainers.containers.VncRecordingContainer.VncRecordingFormat
3032

@@ -46,7 +48,7 @@ class GrailsGebSettings {
4648
public static int DEFAULT_TIMEOUT_PAGE_LOAD = 300
4749
public static int DEFAULT_TIMEOUT_SCRIPT = 30
4850

49-
String tracingEnabled
51+
boolean tracingEnabled
5052
String recordingDirectoryName
5153
String reportingDirectoryName
5254
boolean restartRecordingContainerPerTest
@@ -56,10 +58,13 @@ class GrailsGebSettings {
5658
int implicitlyWait
5759
int pageLoadTimeout
5860
int scriptTimeout
61+
5962
boolean atCheckWaiting
63+
Number timeout
64+
Number retryInterval
6065

6166
GrailsGebSettings(LocalDateTime startTime) {
62-
tracingEnabled = System.getProperty('grails.geb.tracing.enabled', 'false')
67+
tracingEnabled = getBooleanProperty('grails.geb.tracing.enabled', false)
6368
recordingDirectoryName = System.getProperty('grails.geb.recording.directory', 'build/gebContainer/recordings')
6469
reportingDirectoryName = System.getProperty('grails.geb.reporting.directory', 'build/gebContainer/reports')
6570
recordingMode = VncRecordingMode.valueOf(
@@ -76,6 +81,8 @@ class GrailsGebSettings {
7681
pageLoadTimeout = getIntProperty('grails.geb.timeouts.pageLoad', DEFAULT_TIMEOUT_PAGE_LOAD)
7782
scriptTimeout = getIntProperty('grails.geb.timeouts.script', DEFAULT_TIMEOUT_SCRIPT)
7883
atCheckWaiting = getBooleanProperty('grails.geb.atCheckWaiting', DEFAULT_AT_CHECK_WAITING)
84+
timeout = getNumberProperty('grails.geb.timeouts.timeout', Wait.DEFAULT_TIMEOUT)
85+
retryInterval = getNumberProperty('grails.geb.timeouts.retryInterval', Wait.DEFAULT_RETRY_INTERVAL)
7986
this.startTime = startTime
8087
}
8188

@@ -87,6 +94,27 @@ class GrailsGebSettings {
8794
Integer.getInteger(propertyName, defaultValue) ?: defaultValue
8895
}
8996

97+
private static Number getNumberProperty(String propertyName, Number defaultValue) {
98+
def propValue = System.getProperty(propertyName)
99+
if (propValue) {
100+
try {
101+
if (propValue.contains('.')) {
102+
return Double.parseDouble(propValue)
103+
} else {
104+
return Integer.parseInt(propValue)
105+
}
106+
} catch (NumberFormatException ignored) {
107+
log.warn(
108+
"Could not parse property [{}] with value [{}] as a Number. Using default value [{}] instead.",
109+
propertyName,
110+
propValue,
111+
defaultValue
112+
)
113+
}
114+
}
115+
return defaultValue
116+
}
117+
90118
boolean isRecordingEnabled() {
91119
recordingMode != VncRecordingMode.SKIP
92120
}

grails-geb/src/testFixtures/groovy/grails/plugin/geb/WebDriverContainerHolder.groovy

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ import org.codehaus.groovy.runtime.InvokerHelper
3030

3131
import com.github.dockerjava.api.model.ContainerNetwork
3232
import geb.Browser
33+
import geb.Configuration
3334
import geb.ConfigurationLoader
3435
import geb.spock.SpockGebTestManagerBuilder
3536
import geb.test.GebTestManager
37+
import geb.waiting.Wait
3638
import org.openqa.selenium.SessionNotCreatedException
3739
import org.openqa.selenium.chrome.ChromeOptions
3840
import org.openqa.selenium.remote.RemoteWebDriver
@@ -150,7 +152,7 @@ class WebDriverContainerHolder {
150152
)
151153

152154
container.with {
153-
withEnv('SE_ENABLE_TRACING', settings.tracingEnabled)
155+
withEnv('SE_ENABLE_TRACING', settings.tracingEnabled.toString())
154156
withAccessToHost(true)
155157
withImagePullPolicy(PullPolicy.ageBased(Duration.of(1, ChronoUnit.DAYS)))
156158
}
@@ -252,9 +254,12 @@ class WebDriverContainerHolder {
252254
browser.driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(settings.pageLoadTimeout))
253255
if (settings.scriptTimeout != DEFAULT_TIMEOUT_SCRIPT)
254256
browser.driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(settings.scriptTimeout))
255-
if (settings.atCheckWaiting != DEFAULT_AT_CHECK_WAITING) {
257+
if (settings.atCheckWaiting != DEFAULT_AT_CHECK_WAITING)
256258
browser.config.atCheckWaiting = settings.atCheckWaiting
257-
}
259+
if (settings.timeout != Wait.DEFAULT_TIMEOUT)
260+
(browser.config.rawConfig.waiting as ConfigObject).timeout = settings.timeout
261+
if (settings.retryInterval != Wait.DEFAULT_RETRY_INTERVAL)
262+
(browser.config.rawConfig.waiting as ConfigObject).retryInterval = settings.retryInterval
258263
}
259264

260265
private static void startContainer(BrowserWebDriverContainer container, DockerImageName dockerImageName, String customBrowser) {

0 commit comments

Comments
 (0)