Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class GrailsGebSettings {

private static VncRecordingMode DEFAULT_RECORDING_MODE = VncRecordingMode.SKIP
private static VncRecordingFormat DEFAULT_RECORDING_FORMAT = VncRecordingFormat.MP4
private static int DEFAULT_TIMEOUT_IMPLICITLY_WAIT = 0
private static int DEFAULT_TIMEOUT_PAGE_LOAD = 300
private static int DEFAULT_TIMEOUT_SCRIPT = 30
public static int DEFAULT_TIMEOUT_IMPLICITLY_WAIT = 0
public static int DEFAULT_TIMEOUT_PAGE_LOAD = 300
public static int DEFAULT_TIMEOUT_SCRIPT = 30

String tracingEnabled
String recordingDirectoryName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import groovy.util.logging.Slf4j
import com.github.dockerjava.api.model.ContainerNetwork
import geb.Browser
import geb.Configuration
import geb.ConfigurationLoader
import geb.spock.SpockGebTestManagerBuilder
import geb.test.GebTestManager
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.remote.RemoteWebDriver
import org.spockframework.runtime.extension.IMethodInvocation
Expand Down Expand Up @@ -114,50 +114,82 @@ class WebDriverContainerHolder {
grailsGebSettings.recordingFormat
)

Map prefs = [
'credentials_enable_service': false,
'profile.password_manager_enabled': false,
'profile.password_manager_leak_detection': false
]

ChromeOptions chromeOptions = new ChromeOptions()
// TODO: guest would be preferred, but this causes issues with downloads
// see https://issues.chromium.org/issues/42323769
// chromeOptions.addArguments("--guest")
chromeOptions.setExperimentalOption('prefs', prefs)

currentContainer.tap {
currentContainer.with {
withEnv('SE_ENABLE_TRACING', grailsGebSettings.tracingEnabled)
withAccessToHost(true)
withImagePullPolicy(PullPolicy.ageBased(Duration.of(1, ChronoUnit.DAYS)))
withCapabilities(chromeOptions)
start()
}
if (hostnameChanged) {
currentContainer.execInContainer('/bin/sh', '-c', "echo '$hostIp\t${currentConfiguration.hostName}' | sudo tee -a /etc/hosts")
}

ConfigObject configObject = new ConfigObject()
// Create a Geb Configuration the same way as an empty Browser constructor would do
Configuration gebConfig = new ConfigurationLoader().conf

// Ensure driver points to re-initialized container with correct host
// Driver is explicitly quit by us in stop() method to fulfill our resulting responsibility
gebConfig.cacheDriver = false

// "If driver caching is disabled then this setting defaults to true" - we override to false
gebConfig.quitDriverOnBrowserReset = false

gebConfig.baseUrl = currentContainer.seleniumAddress.toString()
if (currentConfiguration.reporting) {
configObject.reportsDir = grailsGebSettings.reportingDirectory
configObject.reporter = (invocation.sharedInstance as ContainerGebSpec).createReporter()
}
if (currentConfiguration.fileDetector != NullContainerFileDetector) {
ServiceRegistry.setInstance(ContainerFileDetector, currentConfiguration.fileDetector)
gebConfig.reportsDir = grailsGebSettings.reportingDirectory
gebConfig.reporter = (invocation.sharedInstance as ContainerGebSpec).createReporter()
}

currentBrowser = new Browser(new Configuration(configObject, new Properties(), null, null))
if (gebConfig.driverConf instanceof RemoteWebDriver) {
// Similar to Browser#getDriverConf's Exception
throw new IllegalStateException(
"The 'driver' config value is an instance of RemoteWebDriver. " +
'You need to wrap the driver instance in a closure.'
)
}
if (gebConfig.driverConf == null) {
// If no driver was set in GebConfig.groovy, default to Chrome
gebConfig.driverConf = { ->
log.info('Using default Chrome RemoteWebDriver for {}', currentContainer.seleniumAddress)
new RemoteWebDriver(currentContainer.seleniumAddress, new ChromeOptions().tap {
// See https://issues.chromium.org/issues/42323769
setExperimentalOption('prefs', [
'credentials_enable_service': false,
'profile.password_manager_enabled': false,
'profile.password_manager_leak_detection': false
])
})
}
}

WebDriver driver = new RemoteWebDriver(currentContainer.seleniumAddress, chromeOptions)
ContainerFileDetector fileDetector = ServiceRegistry.getInstance(ContainerFileDetector, DefaultContainerFileDetector)
((RemoteWebDriver) driver).setFileDetector(fileDetector)
driver.manage().timeouts().with {
implicitlyWait(Duration.ofSeconds(grailsGebSettings.implicitlyWait))
pageLoadTimeout(Duration.ofSeconds(grailsGebSettings.pageLoadTimeout))
scriptTimeout(Duration.ofSeconds(grailsGebSettings.scriptTimeout))
// If `GebConfig` instantiates a `RemoteWebDriver` without using it's `remoteAddress` constructor,
// the `RemoteWebDriver` will be instantiated using the `webdriver.remote.server` system property.
String existingPropertyValue = System.getProperty('webdriver.remote.server')
System.setProperty('webdriver.remote.server', currentContainer.seleniumAddress.toString())
gebConfig.driver // This will implicitly call `createDriver()`

// Restore the `webdriver.remote.server` system property
if (existingPropertyValue == null) {
System.clearProperty('webdriver.remote.server')
} else {
System.setProperty('webdriver.remote.server', existingPropertyValue)
}

currentBrowser.driver = driver
currentBrowser = new Browser(gebConfig)

if (currentConfiguration.fileDetector != NullContainerFileDetector) {
ServiceRegistry.setInstance(ContainerFileDetector, currentConfiguration.fileDetector)
}
ContainerFileDetector fileDetector = ServiceRegistry.getInstance(ContainerFileDetector, DefaultContainerFileDetector)
((RemoteWebDriver) currentBrowser.driver).setFileDetector(fileDetector)

// Overwrite `GebConfig` timeouts with values explicitly set in `GrailsGebSettings` (via system properties)
if (grailsGebSettings.implicitlyWait != GrailsGebSettings.DEFAULT_TIMEOUT_IMPLICITLY_WAIT)
currentBrowser.driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(grailsGebSettings.implicitlyWait))
if (grailsGebSettings.pageLoadTimeout != GrailsGebSettings.DEFAULT_TIMEOUT_PAGE_LOAD)
currentBrowser.driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(grailsGebSettings.pageLoadTimeout))
if (grailsGebSettings.scriptTimeout != GrailsGebSettings.DEFAULT_TIMEOUT_SCRIPT)
currentBrowser.driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(grailsGebSettings.scriptTimeout))

// There's a bit of a chicken and egg problem here: the container & browser are initialized when
// the static/shared fields are initialized, which is before the grails server has started so the
Expand Down
82 changes: 82 additions & 0 deletions grails-test-examples/geb-gebconfig/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

apply plugin: 'groovy'
apply plugin: 'org.apache.grails.gradle.grails-web'
apply plugin: 'org.apache.grails.gradle.grails-gsp'
apply plugin: 'cloud.wondrify.asset-pipeline'

group = 'org.demo.spock'
version = projectVersion

dependencies {

implementation platform(project(':grails-bom'))

implementation 'org.apache.grails:grails-core'
implementation 'org.apache.grails:grails-logging'
implementation 'org.apache.grails:grails-databinding'
implementation 'org.apache.grails:grails-i18n'
implementation 'org.apache.grails:grails-interceptors'
implementation 'org.apache.grails:grails-rest-transforms'
implementation 'org.apache.grails:grails-services'
implementation 'org.apache.grails:grails-url-mappings'
implementation 'org.apache.grails:grails-web-boot'
implementation 'org.apache.grails:grails-gsp'
if(System.getenv('SITEMESH3_TESTING_ENABLED') == 'true') {
implementation 'org.apache.grails:grails-sitemesh3'
}
else {
implementation 'org.apache.grails:grails-layout'
}
implementation 'org.apache.grails:grails-data-hibernate5'
implementation 'org.apache.grails:grails-scaffolding'
implementation 'org.springframework.boot:spring-boot-autoconfigure'
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-logging'
implementation 'org.springframework.boot:spring-boot-starter-tomcat'
implementation 'org.springframework.boot:spring-boot-starter-validation'

testAndDevelopmentOnly platform(project(':grails-bom'))
testAndDevelopmentOnly 'org.webjars.npm:bootstrap'
testAndDevelopmentOnly 'org.webjars.npm:jquery'

runtimeOnly 'cloud.wondrify:asset-pipeline-grails'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'org.apache.tomcat:tomcat-jdbc'
runtimeOnly 'org.fusesource.jansi:jansi'

testImplementation 'org.apache.grails:grails-testing-support-datamapping'
testImplementation 'org.apache.grails:grails-testing-support-web'
testImplementation 'org.spockframework:spock-core'

integrationTestImplementation testFixtures('org.apache.grails:grails-geb')
}

//tasks.withType(Test).configureEach {
// //systemProperty('grails.geb.recording.mode', 'RECORD_ALL')
//}

apply {
from rootProject.layout.projectDirectory.file('gradle/functional-test-config.gradle')
from rootProject.layout.projectDirectory.file('gradle/java-config.gradle')
from rootProject.layout.projectDirectory.file('gradle/test-webjar-asset-config.gradle')
from rootProject.layout.projectDirectory.file('gradle/grails-extension-gradle-config.gradle')
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Loading