Created
March 30, 2019 12:07
-
-
Save mkutz/4f40658b2a35e9355633abb8534989ff to your computer and use it in GitHub Desktop.
Sophisticated GebConfig.groovy using headless or testcontainers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.github.bonigarcia.wdm.WebDriverManager | |
import org.openqa.selenium.Platform | |
import org.openqa.selenium.chrome.ChromeDriver | |
import org.openqa.selenium.chrome.ChromeOptions | |
import org.openqa.selenium.firefox.FirefoxDriver | |
import org.openqa.selenium.firefox.FirefoxOptions | |
import org.openqa.selenium.remote.CapabilityType | |
import org.openqa.selenium.remote.DesiredCapabilities | |
import org.testcontainers.containers.BrowserWebDriverContainer | |
/* | |
* Configuration script for Geb tests. Configuration values might be overwritten using system properties or may be | |
* during runtime in Groovy code. | |
* | |
* See http://www.gebish.org/manual/current/configuration.html for further details. | |
*/ | |
/* put a directory to put reports in here (only filled by ReportingSpecs */ | |
reportsDir = new File("pom.xml").exists() ? "target/geb-reports" : "build/reports/geb" | |
/* only report if test failed */ | |
reportOnTestFailureOnly = false | |
/* clear cookies after each test */ | |
autoClearCookies = true | |
/* Implicit waiting timings of any element */ | |
waiting { | |
timeout = 10 | |
retryInterval = 1 | |
includeCauseInMessage = true | |
} | |
/* don not set this to true, if you need waiting, do it in the at-block! */ | |
atCheckWaiting = false | |
baseUrl = "https://shop-${System.getProperty("testEnvironment", "int") == "int" ? "test" : "preprod"}.rewe.de" | |
driver = { | |
final String browserString = System.getProperty("testBrowser", "chrome").toLowerCase() | |
final boolean headless = browserString.contains("headless") | |
final boolean docker = browserString.contains("docker") | |
final String browser = browserString - "headless" - "docker" | |
if (docker) { | |
DesiredCapabilities capabilities = new DesiredCapabilities(browser, "", Platform.ANY) | |
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true) | |
BrowserWebDriverContainer container = new BrowserWebDriverContainer() | |
.withCapabilities(capabilities) | |
container.start() | |
return container.webDriver | |
} | |
if (browser == "chrome") { | |
WebDriverManager.chromedriver().setup() | |
ChromeOptions options = new ChromeOptions() | |
if (headless) { | |
options.headless = true | |
} | |
return new ChromeDriver(options) | |
} | |
else if (browser == "firefox") { | |
WebDriverManager.firefoxdriver().setup() | |
FirefoxOptions options = new FirefoxOptions() | |
if (headless) { | |
options.headless = true | |
} | |
return new FirefoxDriver(options) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment