From 4075a38e0fdff878268560b626ebb790e3644dda Mon Sep 17 00:00:00 2001 From: Jonny Carter Date: Mon, 23 Dec 2024 12:01:16 -0600 Subject: [PATCH] WIP - get sample configs from files --- .../configuration/DriverConfigSpec.groovy | 21 +++++-------------- .../basicFirefoxDriverConfigScript.groovy | 3 +++ .../headlessFirefoxDriverConfigScript.groovy | 8 +++++++ .../src/docs/asciidoc/060-configuration.adoc | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 doc/manual-snippets/src/test/resources/basicFirefoxDriverConfigScript.groovy create mode 100644 doc/manual-snippets/src/test/resources/headlessFirefoxDriverConfigScript.groovy diff --git a/doc/manual-snippets/src/test/groovy/configuration/DriverConfigSpec.groovy b/doc/manual-snippets/src/test/groovy/configuration/DriverConfigSpec.groovy index 1711428e5..e19fa18b4 100644 --- a/doc/manual-snippets/src/test/groovy/configuration/DriverConfigSpec.groovy +++ b/doc/manual-snippets/src/test/groovy/configuration/DriverConfigSpec.groovy @@ -18,6 +18,7 @@ */ package configuration +import geb.ConfigurationLoader import geb.driver.CachingDriverFactory import geb.fixture.HeadlessTestSupport import geb.test.StandaloneWebDriverServer @@ -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 diff --git a/doc/manual-snippets/src/test/resources/basicFirefoxDriverConfigScript.groovy b/doc/manual-snippets/src/test/resources/basicFirefoxDriverConfigScript.groovy new file mode 100644 index 000000000..c8c444c60 --- /dev/null +++ b/doc/manual-snippets/src/test/resources/basicFirefoxDriverConfigScript.groovy @@ -0,0 +1,3 @@ +import org.openqa.selenium.firefox.FirefoxDriver + +driver = { new FirefoxDriver() } diff --git a/doc/manual-snippets/src/test/resources/headlessFirefoxDriverConfigScript.groovy b/doc/manual-snippets/src/test/resources/headlessFirefoxDriverConfigScript.groovy new file mode 100644 index 000000000..c2138c5a0 --- /dev/null +++ b/doc/manual-snippets/src/test/resources/headlessFirefoxDriverConfigScript.groovy @@ -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) +} diff --git a/doc/manual/src/docs/asciidoc/060-configuration.adoc b/doc/manual/src/docs/asciidoc/060-configuration.adoc index 1bf8244f2..1123a1cf3 100644 --- a/doc/manual/src/docs/asciidoc/060-configuration.adoc +++ b/doc/manual/src/docs/asciidoc/060-configuration.adoc @@ -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. @@ -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. -==== \ No newline at end of file +====