Skip to content

Commit 81511cb

Browse files
committed
Provide install command for geb plugin to configure selenium drivers
Closes gh-1281
1 parent 788f94c commit 81511cb

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import grails.plugin.geb.GebGrailsPlugin
2+
3+
namespace 'geb'
4+
description "Install Geb", "grace geb:install"
5+
visible false
6+
7+
URL gebConfig = GebGrailsPlugin.getResource('/META-INF/templates/GebConfig.groovy')
8+
File projectDir = executionContext.baseDir
9+
File resourcesDir = new File(projectDir, 'src/integration-test/resources')
10+
File gebFile = new File(resourcesDir, 'GebConfig.groovy')
11+
File buildFile = new File(projectDir, 'build.gradle')
12+
13+
if (!resourcesDir.exists()) {
14+
resourcesDir.mkdir()
15+
}
16+
17+
use(FileCategory) {
18+
// Copy GebConfig.groovy to 'src/integration-test/resources'
19+
gebFile << gebConfig
20+
21+
// Set system properties in the build.gradle
22+
buildFile.insertAfter 'useJUnitPlatform()', '''
23+
systemProperty 'geb.env', System.getProperty('geb.env')
24+
systemProperty 'geb.build.reportsDir', reporting.file('geb/integrationTest')'''
25+
}
26+
27+
28+
class FileCategory {
29+
30+
def static leftShift(File file, URL url) {
31+
url.withInputStream { is ->
32+
file.withOutputStream { os ->
33+
def bs = new BufferedOutputStream(os)
34+
bs << is
35+
}
36+
}
37+
}
38+
39+
def static leftShift(File dest, File src) {
40+
src.withInputStream { is ->
41+
dest.withOutputStream { os ->
42+
def bs = new BufferedOutputStream(os)
43+
bs << is
44+
}
45+
}
46+
}
47+
48+
def static insertAfter(File file, String searchString, String text) {
49+
if (!file?.exists()) return
50+
String content = file.text
51+
if (content?.indexOf(searchString) <= 0) return
52+
String before = content.takeBefore(searchString)
53+
String after = content.takeAfter(searchString)
54+
StringBuffer newContent = new StringBuffer()
55+
newContent << before << searchString << text << after
56+
file.text = newContent
57+
}
58+
59+
def static insertBefore(File file, String searchString, String text) {
60+
if (!file?.exists()) return
61+
String content = file.text
62+
if (content?.indexOf(searchString) <= 0) return
63+
String before = content.takeBefore(searchString)
64+
String after = content.takeAfter(searchString)
65+
StringBuffer newContent = new StringBuffer()
66+
newContent << before << text << searchString << after
67+
file.text = newContent
68+
}
69+
}
70+
71+
consoleLogger.addStatus "Copying 'GebConfig.groovy' to 'src/integration-test/resources'"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import org.openqa.selenium.chrome.ChromeDriver
2+
import org.openqa.selenium.chrome.ChromeOptions
3+
import org.openqa.selenium.firefox.FirefoxDriver
4+
5+
environments {
6+
7+
// run via “./gradlew -Dgeb.env=chrome iT”
8+
chrome {
9+
driver = { new ChromeDriver() }
10+
}
11+
12+
// run via “./gradlew -Dgeb.env=chromeHeadless iT”
13+
chromeHeadless {
14+
driver = {
15+
ChromeOptions o = new ChromeOptions()
16+
o.addArguments('headless')
17+
new ChromeDriver(o)
18+
}
19+
}
20+
21+
// run via “./gradlew -Dgeb.env=firefox iT”
22+
firefox {
23+
driver = { new FirefoxDriver() }
24+
}
25+
}

0 commit comments

Comments
 (0)