Skip to content

Commit

Permalink
Ensure all browsers launched by tests are headless and remove the XVFB
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Pounder authored and Adam Pounder committed Oct 28, 2024
1 parent bd4c683 commit d73317c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 0 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ jobs:
- gradle-home-manual-machine
- run:
command: |
export WORKING_DIRECTORY=`pwd`
Xvfb :99 -screen 1 1280x1024x16 -nolisten tcp > /dev/null 2>&1 &
export DISPLAY=:99
./gradlew --no-daemon --max-workers 4 --parallel -Pci :doc:manual-snippets:check :doc:manual-snippets:fixtures:check :doc:manual-snippets:real-browser:check :doc:manual:build :doc:asciidoctor-extension:check
- run: &collectTestResults
name: Copy all test results to a directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ package configuration

import geb.driver.CachingDriverFactory
import geb.test.StandaloneWebDriverServer
import org.openqa.selenium.Capabilities
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxOptions
import org.openqa.selenium.htmlunit.HtmlUnitDriver
import org.openqa.selenium.remote.RemoteWebDriver
import spock.lang.AutoCleanup
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll

import java.lang.reflect.Constructor

class DriverConfigSpec extends Specification implements InlineConfigurationLoader {

@Shared
Expand All @@ -33,6 +37,18 @@ class DriverConfigSpec extends Specification implements InlineConfigurationLoade

def setupSpec() {
CachingDriverFactory.clearCacheAndQuitDriver()

FirefoxDriver.metaClass.constructor = { ->
new FirefoxDriver(new FirefoxOptions().addArguments("--headless"))
}

Constructor<RemoteWebDriver> ctor = RemoteWebDriver.getConstructor(URL, Capabilities)
RemoteWebDriver.metaClass.constructor = { url, Capabilities options ->
if (options in FirefoxOptions) {
options.addArguments("--headless")
}
ctor.newInstance(url, options)
}
}

def "configuring driver using closure"() {
Expand Down

0 comments on commit d73317c

Please sign in to comment.