I am attempting to run a test that first opens chrome (performs test) and then opens up IE (performs test)
Even though I have all my firefox code commented out, geb decides to open up firefox instead of IE for some reason.
here is my build.gradle:
import org.apache.tools.ant.taskdefs.condition.Os
def properties = new Properties()
new File('/ProgramData/geb.properties').withInputStream {
properties.load(it)
}
ext {
// The drivers we want to use
drivers = ["chrome", "internetExplorer"]
ext {
groovyVersion = '2.4.5'
gebVersion = '1.1.1'
seleniumVersion = '2.52.0'
chromeDriverVersion = '2.29'
geckoDriverVersion = '0.18.0'
ieDriverVersion = '2.44.0'
PagesVersion = '4.6-NC'
}
}
apply plugin: "groovy"
apply from: "gradle/idea.gradle"
apply from: "gradle/osSpecificDownloads.gradle"
repositories {
mavenCentral()
}
dependencies {
// If using Spock, need to depend on geb-spock
testCompile "org.gebish:geb-spock:$gebVersion"
testCompile("org.spockframework:spock-core:1.0-groovy-2.4") {
exclude group: "org.codehaus.groovy"
}
testCompile "org.codehaus.groovy:groovy-all:$groovyVersion"
// If using JUnit, need to depend on geb-junit (3 or 4)
testCompile "org.gebish:geb-junit4:$gebVersion"
testCompile (group: 'com.myGroup', name: 'GebPageObjects', version: "${PagesVersion}"){changing = true} // re-download dependency after every build.
testCompile (group: 'com.myGroup', name: 'GebPageObjects', version: "${PagesVersion}",classifier: 'sources'){changing = true} // re-download dependency after every build.
// Drivers
testCompile "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
// testCompile "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
testCompile "org.seleniumhq.selenium:selenium-ie-driver:$seleniumVersion"
// using a custom version of phantomjs driver for now as the original one does not support WebDriver > 2.43.1
testCompile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
testCompile 'org.json:json:20151123'
}
drivers.each { driver ->
task "${driver}Test"(type: Test) {
reports {
html.destination = reporting.file("$name/tests")
junitXml.destination = file("$buildDir/test-results/$name")
}
outputs.upToDateWhen { false } // Always run tests
systemProperty "geb.build.reportsDir", reporting.file("$name/geb")
systemProperty "geb.env", driver
// If you wanted to set the baseUrl in your build…
// systemProperty "geb.build.baseUrl", "http://myapp.com"
}
}
chromeTest {
dependsOn unzipChromeDriver
def chromedriverFilename = Os.isFamily(Os.FAMILY_WINDOWS) ?
"chromedriver.exe" : "chromedriver"
systemProperty "webdriver.chrome.driver", new File(unzipChromeDriver.outputs.files.singleFile, chromedriverFilename).absolutePath
}
internetExplorerTest {
dependsOn unzipIEDriver
def iedriverFilename = Os.isFamily(Os.FAMILY_WINDOWS) ? "IEDriverServer.exe" : "IEDriverServer"
systemProperty "webdriver.ie.driver", new File(unzipIEDriver.outputs.files.singleFile, iedriverFilename).absolutePath
}
//firefoxTest {
// dependsOn unzipGeckoDriver
// def geckodriverFilename = Os.isFamily(Os.FAMILY_WINDOWS) ? "geckodriver.exe" : "geckodriver"
// def geckodriverFile = new File(unzipGeckoDriver.outputs.files.singleFile, geckodriverFilename)
// systemProperty "webdriver.gecko.driver", geckodriverFile.absolutePath
//}
task deleted(type: Delete){
try{
delete "${buildDir}"
}
catch(Throwable t){
delete "${buildDir}"
}
}
test {
dependsOn drivers.collect { tasks["${it}Test"] }
enabled = false
}
clean{
dependsOn deleted
enabled = false
}
apply from: "gradle/ci.gradle"
Here is part of my gebConfig file:
environments {
// run via “./gradlew chromeTest”
// See: http://code.google.com/p/selenium/wiki/ChromeDriver
chrome {
driver = {
ChromeOptions options = new ChromeOptions();
// options.addArguments("--disable-gpu");
new ChromeDriver(options)
}
}
ie {
driver = {
// System.setProperty("webdriver.ie.driver", new File("C:/dev/Selenium/iexploredriver.exe").getAbsolutePath())
new InternetExplorerDriver()
}
}
}
Finnally here are a few tasks from OsSpeicifcDownloads.gradle which are relevant:
task downloadInternetExplorerDriver {
def outputFile = file("$buildDir/webdriver/IEdriver.zip")
inputs.property("IEDriverVersion", ieDriverVersion)
outputs.file(outputFile)
doLast {
def driverOsFilenamePart
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
driverOsFilenamePart = "x64"
} else if (Os.isFamily(Os.FAMILY_MAC)) {
driverOsFilenamePart = "mac32"
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
driverOsFilenamePart = Os.isArch("amd64") ? "linux64" : "linux32"
}
println "https://code.google.com/p/selenium/downloads/detail?name=IEDriverServer_${driverOsFilenamePart}_${ieDriverVersion}"
FileUtils.copyURLToFile(new URL("http://selenium-release.storage.googleapis.com/2.44/IEDriverServer_${driverOsFilenamePart}_${ieDriverVersion}.zip"), outputFile)
}
}
task unzipIEDriver(type: Copy) {
def outputDir = file("$buildDir/webdriver/IEdriver")
dependsOn downloadInternetExplorerDriver
outputs.dir(outputDir)
from(zipTree(downloadInternetExplorerDriver.outputs.files.singleFile))
into(outputDir)
}
Any Ideas as to why Firefox is launched instead of IE?
I should also add that Both Chrome and IE drivers appear unzipped in my build dir, and there is no firefox driver present.
Here is a snippet from the console output:
:downloadInternetExplorerDriver
https://code.google.com/p/selenium/downloads/detail?
name=IEDriverServer_x64_2.44.0
:unzipIEDriver
:internetExplorerTest
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
As you can see it claims to be running internetExplorerTest, but then promptly tries to run fireFox. Why?
I execute my script by calling: gradlew.bat clean build test
You need to change:
drivers = ["chrome", "internetExplorer"]
to:
drivers = ["chrome", "ie"]
Because this code:
drivers.each { driver ->
task "${driver}Test"(type: Test) {
reports {
html.destination = reporting.file("$name/tests")
junitXml.destination = file("$buildDir/test-results/$name")
}
outputs.upToDateWhen { false } // Always run tests
systemProperty "geb.build.reportsDir", reporting.file("$name/geb")
systemProperty "geb.env", driver
// If you wanted to set the baseUrl in your build…
// systemProperty "geb.build.baseUrl", "http://myapp.com"
}
}
Is saying for each variable driver in drivers ("chrome", "internetExplorer") set the geb.env to that value.
geb.env is being set to "internetExplorer" but your gebConfig only has driver definitions for "chrome" and "ie" so it's going to use the defaullt driver which is firefox.
chrome {
driver = {
ChromeOptions options = new ChromeOptions();
// options.addArguments("--disable-gpu");
new ChromeDriver(options)
}
}
ie {
driver = {
// System.setProperty("webdriver.ie.driver", new File("C:/dev/Selenium/iexploredriver.exe").getAbsolutePath())
new InternetExplorerDriver()
}
}
Section 7.2.1.1 of the geb manual has an example:
environments {
// when system property 'geb.env' is set to 'win-ie' use a remote IE driver
'win-ie' {
driver = {
new RemoteWebDriver(new URL("http://windows.ci-server.local"), DesiredCapabilities.internetExplorer())
}
}