-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the examples in the section on configuring navigator factory exe…
…cutable. Part of geb/issues#350
- Loading branch information
Showing
5 changed files
with
138 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
35 changes: 35 additions & 0 deletions
35
doc/new-manual/src/test/groovy/configuration/InlineConfigurationLoader.groovy
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2015 the original author or authors. | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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. | ||
*/ | ||
package configuration | ||
|
||
import geb.Configuration | ||
import geb.ConfigurationLoader | ||
|
||
trait InlineConfigurationLoader implements TemporaryFolderProvider { | ||
Configuration config | ||
|
||
void configScript(String script) { | ||
configScript(null, script) | ||
} | ||
|
||
void configScript(String env, String script) { | ||
def classLoader = new GroovyClassLoader(getClass().classLoader) | ||
classLoader.addClasspath(temporaryFolder.root.absolutePath) | ||
def configFile = temporaryFolder.newFile() | ||
configFile << script | ||
config = new ConfigurationLoader(env, null, classLoader).getConf(configFile.name) | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
doc/new-manual/src/test/groovy/configuration/NavigatorFactoryConfigSpec.groovy
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2015 the original author or authors. | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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. | ||
*/ | ||
package configuration | ||
|
||
import geb.Configuration | ||
import geb.navigator.EmptyNavigator | ||
import geb.navigator.NonEmptyNavigator | ||
import geb.test.GebSpecWithCallbackServer | ||
import groovy.transform.InheritConstructors | ||
import org.junit.ClassRule | ||
import org.junit.rules.TemporaryFolder | ||
import spock.lang.Shared | ||
|
||
class NavigatorFactoryConfigSpec extends GebSpecWithCallbackServer implements InlineConfigurationLoader { | ||
|
||
@ClassRule | ||
@Shared | ||
TemporaryFolder tempDir | ||
|
||
TemporaryFolder getTemporaryFolder() { | ||
tempDir | ||
} | ||
|
||
@Override | ||
Configuration createConf() { | ||
configScript """ | ||
import configuration.MyCustomNavigator | ||
import configuration.MyCustomEmptyNavigator | ||
// tag::config[] | ||
import geb.Browser | ||
import org.openqa.selenium.WebElement | ||
innerNavigatorFactory = { Browser browser, List<WebElement> elements -> | ||
elements ? new MyCustomNavigator(browser, elements) : new MyCustomEmptyNavigator() | ||
} | ||
// end::config[] | ||
reportsDir = "${super.createConf().reportsDir.absolutePath}" | ||
""" | ||
config | ||
} | ||
|
||
def "specifying custom navigator implementation"() { | ||
when: | ||
html "" | ||
|
||
then: | ||
$() instanceof MyCustomNavigator | ||
$("idontexist") instanceof MyCustomEmptyNavigator | ||
} | ||
} | ||
|
||
@InheritConstructors | ||
class MyCustomNavigator extends NonEmptyNavigator { | ||
} | ||
|
||
@InheritConstructors | ||
class MyCustomEmptyNavigator extends EmptyNavigator { | ||
} |
22 changes: 22 additions & 0 deletions
22
doc/new-manual/src/test/groovy/configuration/TemporaryFolderProvider.groovy
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2015 the original author or authors. | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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. | ||
*/ | ||
package configuration | ||
|
||
import org.junit.rules.TemporaryFolder | ||
|
||
interface TemporaryFolderProvider { | ||
TemporaryFolder getTemporaryFolder() | ||
} |