Skip to content

Commit d336f0b

Browse files
authored
Merge branch '4.2.x' into geb-133-serviceloader
2 parents 4503fb5 + 9ddf998 commit d336f0b

File tree

5 files changed

+38
-5
lines changed

5 files changed

+38
-5
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ Optionally, in specific test classes, either call [`ContainerGebTestDescriptionS
9090
in a Spock `setupSpec` method to apply your naming convention (And use a `cleanupSpec` to limit this to one class),
9191
or set the `testDescription` Property on your ContainerGebConfiguration annotation.
9292

93+
#### Remove Implicit Wait
94+
95+
* `grails.geb.timeouts.implicitlyWait`
96+
* purpose: amount of time the driver should wait when searching for an element if it is not immediately present.
97+
* defaults to `0` seconds, which means that if an element is not found, it will immediately return an error.
98+
* Warning: Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times.
99+
Consult the [Geb](https://www.gebish.org/manual/current/#implicit-assertions-waiting)
100+
and/or [Selenium](https://www.selenium.dev/documentation/webdriver/waits/) documentation for details.
101+
* `grails.geb.timeouts.pageLoad`
102+
* purpose: amount of time to wait for a page load to complete before throwing an error.
103+
* defaults to `300` seconds
104+
* `grails.geb.timeouts.script`
105+
* purpose: amount of time to wait for an asynchronous script to finish execution before throwing an error.
106+
* defaults to `30` seconds
107+
93108
#### Observability and Tracing
94109
Selenium integrates with [OpenTelemetry](https://opentelemetry.io) to support observability and tracing out of the box. By default, Selenium [enables tracing](https://www.selenium.dev/blog/2021/selenium-4-observability).
95110

spock-container-test-app/src/integration-test/groovy/org/demo/spock/RootPageSpec.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package org.demo.spock
33
import geb.report.CompositeReporter
44
import geb.report.PageSourceReporter
55
import geb.report.Reporter
6-
import geb.report.ScreenshotReporter
76
import grails.plugin.geb.ContainerGebConfiguration
87
import grails.plugin.geb.ContainerGebSpec
98
import grails.testing.mixin.integration.Integration
@@ -19,7 +18,7 @@ class RootPageSpec extends ContainerGebSpec {
1918
@Override
2019
Reporter createReporter() {
2120
// Override the default reporter to demonstrate how this can be customized
22-
new CompositeReporter(new ScreenshotReporter(), new PageSourceReporter())
21+
new CompositeReporter(new PageSourceReporter())
2322
}
2423

2524
void 'should display the correct title on the home page'() {

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 original author or authors
2+
* Copyright 2024-2025 original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,13 +37,19 @@ class GrailsGebSettings {
3737

3838
private static VncRecordingMode DEFAULT_RECORDING_MODE = VncRecordingMode.SKIP
3939
private static VncRecordingFormat DEFAULT_RECORDING_FORMAT = VncRecordingFormat.MP4
40+
private static int DEFAULT_TIMEOUT_IMPLICITLY_WAIT = 0
41+
private static int DEFAULT_TIMEOUT_PAGE_LOAD = 300
42+
private static int DEFAULT_TIMEOUT_SCRIPT = 30
4043

4144
String tracingEnabled
4245
String recordingDirectoryName
4346
String reportingDirectoryName
4447
VncRecordingMode recordingMode
4548
VncRecordingFormat recordingFormat
4649
LocalDateTime startTime
50+
int implicitlyWait
51+
int pageLoadTimeout
52+
int scriptTimeout
4753

4854
GrailsGebSettings(LocalDateTime startTime) {
4955
tracingEnabled = System.getProperty('grails.geb.tracing.enabled', 'false')
@@ -55,9 +61,16 @@ class GrailsGebSettings {
5561
recordingFormat = VncRecordingFormat.valueOf(
5662
System.getProperty('grails.geb.recording.format', DEFAULT_RECORDING_FORMAT.name())
5763
)
64+
implicitlyWait = getIntProperty('grails.geb.timeouts.implicitlyWait', DEFAULT_TIMEOUT_IMPLICITLY_WAIT)
65+
pageLoadTimeout = getIntProperty('grails.geb.timeouts.pageLoad', DEFAULT_TIMEOUT_PAGE_LOAD)
66+
scriptTimeout = getIntProperty('grails.geb.timeouts.script', DEFAULT_TIMEOUT_SCRIPT)
5867
this.startTime = startTime
5968
}
6069

70+
private static int getIntProperty(String propertyName, int defaultValue) {
71+
Integer.getInteger(propertyName, defaultValue) ?: defaultValue
72+
}
73+
6174
boolean isRecordingEnabled() {
6275
recordingMode != VncRecordingMode.SKIP
6376
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import groovy.transform.EqualsAndHashCode
2626
import groovy.transform.PackageScope
2727
import groovy.util.logging.Slf4j
2828
import org.openqa.selenium.WebDriver
29+
import org.openqa.selenium.WebDriver.Timeouts
2930
import org.openqa.selenium.chrome.ChromeOptions
3031
import org.openqa.selenium.remote.RemoteWebDriver
3132
import org.spockframework.runtime.extension.IMethodInvocation
@@ -125,7 +126,11 @@ class WebDriverContainerHolder {
125126
currentBrowser = new Browser(new Configuration(configObject, new Properties(), null, null))
126127

127128
WebDriver driver = new RemoteWebDriver(currentContainer.seleniumAddress, new ChromeOptions())
128-
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30))
129+
driver.manage().timeouts().with {
130+
implicitlyWait(Duration.ofSeconds(grailsGebSettings.implicitlyWait))
131+
pageLoadTimeout(Duration.ofSeconds(grailsGebSettings.pageLoadTimeout))
132+
scriptTimeout(Duration.ofSeconds(grailsGebSettings.scriptTimeout))
133+
}
129134

130135
currentBrowser.driver = driver
131136

src/testFixtures/groovy/grails/plugin/geb/support/ReportingSupport.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package grails.plugin.geb.support
1818
import geb.report.CompositeReporter
1919
import geb.report.PageSourceReporter
2020
import geb.report.Reporter
21+
import geb.report.ScreenshotReporter
2122
import grails.plugin.geb.ContainerGebSpec
2223
import groovy.transform.CompileStatic
2324
import groovy.transform.SelfType
@@ -41,6 +42,6 @@ trait ReportingSupport {
4142
* The reporter that Geb should use when reporting is enabled.
4243
*/
4344
Reporter createReporter() {
44-
new CompositeReporter(new PageSourceReporter())
45+
return new CompositeReporter(new PageSourceReporter(), new ScreenshotReporter())
4546
}
4647
}

0 commit comments

Comments
 (0)