Skip to content

Commit

Permalink
WIP - get sample configs from files
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnybot0 committed Dec 23, 2024
1 parent a35598d commit 4075a38
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package configuration

import geb.ConfigurationLoader
import geb.driver.CachingDriverFactory
import geb.fixture.HeadlessTestSupport
import geb.test.StandaloneWebDriverServer
Expand All @@ -41,22 +42,10 @@ class DriverConfigSpec extends Specification implements InlineConfigurationLoade

def "configuring driver using closure"() {
when:
// lang=groovy
configScript """
import org.openqa.selenium.firefox.FirefoxOptions
// tag::configuring_driver[]
// tag::configuring_driver-a[]
import org.openqa.selenium.firefox.FirefoxDriver
driver = {
new FirefoxDriver()
// end::configuring_driver-a[]
${HeadlessTestSupport.headless ? /new FirefoxDriver(new FirefoxOptions().addArguments('--headless'))/ : ''}
// tag::configuring_driver-b[]
}
// end::configuring_driver-b[]
// end::configuring_driver[]
"""
def config = new ConfigurationLoader(null, null, new GroovyClassLoader(DriverConfigSpec.classLoader))
.getConf(
HeadlessTestSupport.headless ? '/headlessFirefoxDriverConfigScript.groovy' : '/basicFirefoxDriverConfigScript.groovy'
)

then:
config.driver instanceof FirefoxDriver
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import org.openqa.selenium.firefox.FirefoxDriver

driver = { new FirefoxDriver() }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxOptions

driver = {
def options = new FirefoxOptions()
options.addArguments('--headless')
new FirefoxDriver(options)
}
4 changes: 2 additions & 2 deletions doc/manual/src/docs/asciidoc/060-configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ In the config script it can be a closure that when invoked with no arguments ret

[source,groovy]
----
include::{snippets-dir}/configuration/DriverConfigSpec.groovy[tag=configuring_driver,indent=0]
include::doc/manual-snippets/src/test/resources/basicFirefoxDriverConfigScript.groovy
----

This is the preferred mechanism, as it allows the most control over the drivers creation and configuration.
Expand Down Expand Up @@ -429,4 +429,4 @@ include::{snippets-dir}/configuration/FunctionalSpec.groovy[tag=runtime_override
====
Bear in mind that since Geb 6.0, one `Configuration` instance is shared between all of the tests.
To avoid configuration runtime overrides bleeding from one test to another, you will have to revert any overrides after the test, like it is done in `cleanup()` of the above example.
====
====

0 comments on commit 4075a38

Please sign in to comment.