Skip to content

Commit bcf4aa6

Browse files
authored
Geb 8 (#15067)
* fix(deps): `geb` v. `7.0` -> `8.0.0` * fix: adapt to changes in Geb 8 Adapt to changed driver creation logic in Geb 8. * refactor(geb): simplifications * docs(geb): improve comments and javadoc * chore(geb): whitespace * fix(geb): reset `webdriver.remote.server` after `RemoteWebDriver` init Reinstate resetting the system property after driver construction. * docs(geb): minor comment improvement * fix(geb): prevent cross-thread leakage of `webdriver.remote.server` Scope the `webdriver.remote.server` System property to the current thread during `RemoteWebDriver` creation, then restore it. This avoids routing later sessions to the wrong endpoint in parallel builds. * fix(geb): allow testing with different browsers This allows using different browsers in `GebConfig.groovy` A `configuredBrowser` property has to be set that matches the browser capabilities used to create the `RemoteWebDriver` to start the correct container for the browser. * chore(geb): formatting * chore(geb): formatting * refactor(geb): simplify system property override * docs(geb): improve javadoc and code comments * fix(geb): resolve trait method conflicts via explicit override * refactor(geb): simplify * chore(geb): formatting * refactor(geb): simplify * test(geb): update test label * docs(geb): add `GebConfig` instructions to README * fix(geb): make inner classes `static` * feedback(geb): rename property to `containerBrowser` * chore(geb): formatting * fix(geb): add message for missing `containerBrowser` Add a more helpful error message in the case where a `containerBrowser` property is missing from `GebConfig.groovy`. * test(geb): make tests more resilient in slow runners * fix(feedback): skip `containerBrowser` validation * refactor(geb): extract methods * fix(geb): move `atCheckWaiting` to CI env variable * fix(geb): feedback - remove container fallback Throw exception when `driver` and `containerBrowser` are mismatched in `GebConfig` instead of falling back to chrome. * fix(geb): system property setting of timeout values * ci: update Geb `atCheckWaiting` system property * chore(geb): formatting * fix(geb): use correct `atCheckWaiting` system property * fix(geb): feedback - use `BigDecimal` in `GrailsGebSettings` * ci: feedback - set `atCheckWaiting` in build file
1 parent 1385520 commit bcf4aa6

32 files changed

+556
-254
lines changed

.github/workflows/gradle.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ jobs:
178178
--continue
179179
--rerun-tasks
180180
--stacktrace
181+
-PgebAtCheckWaiting
181182
-PonlyFunctionalTests
182183
-PskipCodeStyle
183184
-PskipHibernate5Tests

DEVELOPMENT.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ These can be set on the command line like so:
3131

3232
`./gradlew check -PskipCodeStyle`
3333

34+
* `gebAtCheckWaiting` - enables Geb atCheckWaiting
3435
* `onlyCoreTests` - runs tests that do not include mongo, hibernate, or functional
3536
* `onlyFunctionalTests` - runs only grails-test-examples/* tests
3637
* `onlyHibernate5Tests` - runs only a hibernate5 related test

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ allprojects {
7070
url = 'https://repository.apache.org/content/groups/staging'
7171
content {
7272
includeModuleByRegex('org[.]apache[.]grails[.]gradle', 'grails-publish')
73+
includeModuleByRegex('org[.]apache[.]groovy[.]geb', 'geb-.*')
7374
}
7475
mavenContent {
7576
releasesOnly()

dependencies.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ ext {
7676
'bootstrap-icons.version' : '1.13.1',
7777
'bootstrap.version' : '5.3.7',
7878
'commons-codec.version' : '1.18.0',
79-
'geb-spock.version' : '7.0',
79+
'geb-spock.version' : '8.0.0',
8080
'groovy.version' : '4.0.28',
8181
'h2.version' : '2.3.232',
8282
'jackson.version' : '2.19.1',
@@ -106,7 +106,7 @@ ext {
106106
'bootstrap' : "org.webjars.npm:bootstrap:${bomDependencyVersions['bootstrap.version']}",
107107
'bootstrap-icons' : "org.webjars.npm:bootstrap-icons:${bomDependencyVersions['bootstrap-icons.version']}",
108108
'commons-codec' : "commons-codec:commons-codec:${bomDependencyVersions['commons-codec.version']}",
109-
'geb-spock' : "org.gebish:geb-spock:${bomDependencyVersions['geb-spock.version']}",
109+
'geb-spock' : "org.apache.groovy.geb:geb-spock:${bomDependencyVersions['geb-spock.version']}",
110110
'h2' : "com.h2database:h2:${bomDependencyVersions['h2.version']}",
111111
'jquery' : "org.webjars.npm:jquery:${bomDependencyVersions['jquery.version']}",
112112
'liquibase-hibernate5' : "org.liquibase:liquibase:${bomDependencyVersions['liquibase-hibernate5.version']}",

gradle/functional-test-config.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ tasks.withType(Test).configureEach { Test task ->
113113
if (System.getProperty('debug.tests')) {
114114
task.jvmArgs += debugArguments
115115
}
116+
117+
// Make Geb tests more resilient in slow CI environments
118+
if (project.hasProperty('gebAtCheckWaiting')) {
119+
systemProperty('grails.geb.atCheckWaiting.enabled', 'true')
120+
}
116121
}
117122

118123
tasks.named('groovydoc').configure {

grails-doc/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ dependencies {
5353
implementation 'org.testcontainers:testcontainers'
5454
implementation 'org.springframework:spring-core'
5555
implementation 'org.springframework.boot:spring-boot'
56-
implementation 'org.gebish:geb-spock'
56+
implementation 'org.apache.groovy.geb:geb-spock'
5757
}
5858

5959
// this task needs to be here instead of the root since bom resolution only occurs when the java / groovy plugins are applied

grails-geb/README.md

Lines changed: 39 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
@@ -161,6 +177,28 @@ To enable tracing, set the following system property:
161177

162178
This allows you to opt in to tracing when an OpenTelemetry collector is available.
163179

180+
#### GebConfig.groovy and using non-default browser settings
181+
Provide a `GebConfig.groovy` on the test runtime classpath (commonly `src/integration-test/resources`, but any location on the test classpath works) to customize the browser.
182+
183+
To make this work, ensure:
184+
1. The `driver` property in your `GebConfig` is a `Closure` that returns a `RemoteWebDriver` instance.
185+
2. You set a custom `containerBrowser` property so that `ContainerGebSpec` can start a matching container (e.g. "chrome", "edge", "firefox"). For a list of supported browsers, see the [Testcontainers documentation](https://java.testcontainers.org/modules/webdriver_containers/#other-browsers).
186+
3. Your `build.gradle` includes the driver dependency for the chosen browser.
187+
188+
Example `GebConfig.groovy`:
189+
```groovy
190+
driver = {
191+
new RemoteWebDriver(new FireFoxOptions())
192+
}
193+
containerBrowser = 'firefox'
194+
```
195+
Example `build.gradle`:
196+
```groovy
197+
dependencies {
198+
integrationTestImplementation 'org.seleniumhq.selenium:selenium-firefox-driver'
199+
}
200+
```
201+
164202
### GebSpec
165203

166204
If you choose to extend `GebSpec`, you will need to have a [Selenium WebDriver](https://www.selenium.dev/documentation/webdriver/browsers/) installed that matches a browser you have installed on your system.

grails-geb/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ dependencies {
4949
testFixturesCompileOnly 'jakarta.servlet:jakarta.servlet-api'
5050
testFixturesCompileOnly 'org.slf4j:slf4j-simple' // Remove compilation warning about missing slf4j impl
5151

52-
testFixturesApi 'org.gebish:geb-spock'
52+
testFixturesApi 'org.apache.groovy.geb:geb-spock'
5353
testFixturesApi project(':grails-testing-support-core')
5454
testFixturesApi project(':grails-datamapping-core')
5555
testFixturesApi "org.testcontainers:selenium"
@@ -59,7 +59,7 @@ dependencies {
5959
testFixturesImplementation "org.seleniumhq.selenium:selenium-support"
6060

6161
// Added to be able to resolve the geb version from the BOM in the resolveVersions task
62-
compileOnly 'org.gebish:geb-spock'
62+
compileOnly 'org.apache.groovy.geb:geb-spock'
6363
}
6464

6565
apply {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import org.openqa.selenium.remote.FileDetector
2626
* An extension of {@link org.openqa.selenium.remote.FileDetector}
2727
* that will get passed additional parameters from the webdriver container holder.
2828
* <p>
29-
* Implementations must provide a zero-argument constructor to ensure compatibility with {@link java.util.ServiceLoader}.
29+
* Implementations must provide a zero-argument constructor to ensure compatibility
30+
* with {@link java.util.ServiceLoader}.
3031
*
3132
* @see GebRecordingTestListener
3233
*/

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import java.lang.annotation.Target
2626
import org.testcontainers.containers.GenericContainer
2727

2828
/**
29-
* Can be used to configure the protocol and hostname that the container's browser will use
29+
* Can be used to configure the protocol and hostname that the container's browser will use.
3030
*
3131
* @author James Daugherty
3232
* @since 4.1
@@ -53,7 +53,8 @@ import org.testcontainers.containers.GenericContainer
5353
String hostName() default DEFAULT_HOSTNAME_FROM_CONTAINER
5454

5555
/**
56-
* Whether reporting should be enabled for this test. Add a `GebConfig.groovy` to customize the reporter configuration.
56+
* Whether reporting should be enabled for this test.
57+
* Add a `GebConfig.groovy` to customize the reporter configuration.
5758
*/
5859
boolean reporting() default false
5960

@@ -70,7 +71,7 @@ import org.testcontainers.containers.GenericContainer
7071
}
7172

7273
/**
73-
* Inheritable version of {@link ContainerGebConfiguration}
74+
* Inheritable version of {@link ContainerGebConfiguration}.
7475
*
7576
* @since 4.2
7677
*/

0 commit comments

Comments
 (0)