geb.Browser is trying to use FirefoxDriver instead of PhatomJSDriver - gradle

For some reason, my code tries to use the firefox browser when it should be using phantomjs.
My groovy code looks like this:
import geb.Browser
...
env = System.getenv()
def username = env.username
def password = env.password
def gateway = env.gateway
def matcher = gateway =~ /^(https?:\/\/)([^:^\/]*)(:\d*)?(.*)?.*$/
def host = matcher[0][2]
def port = matcher[0][3]
if (env.driver == 'firefox') {
driver = new FirefoxDriver()
} else {
println env.phantomjspath
def caps = DesiredCapabilities.phantomjs()
caps.setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, env.phantomjspath
)
driver = new PhantomJSDriver(caps)
driver.manage().window().setSize(new Dimension(1028, 768))
}
def browser = new Browser(driver: driver)
BiHome = "https://" + username + ":" + password + "#" + host + port + "/gateway/default/BigInsightsWeb/#/welcome"
browser.drive {
go BiHome
// code omitted for brevity
}
browser.close()
Unfortunately, for some reason geb.Browser is trying to use the FirefoxDriver:
:CheckHomePhantomJS
/Users/snowch/Repos/biginsight-examples2/examples/BiginsightsHome/build/webdriver/phantomjs/bin/phantomjs
May 10, 2016 10:13:57 AM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: executable: /Users/snowch/Repos/biginsight-examples2/examples/BiginsightsHome/build/webdriver/phantomjs/bin/phantomjs
May 10, 2016 10:13:57 AM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: port: 19084
May 10, 2016 10:13:57 AM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: arguments: [--webdriver=19084, --webdriver-logfile=/Users/snowch/Repos/biginsight-examples2/examples/BiginsightsHome/phantomjsdriver.log]
May 10, 2016 10:13:57 AM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: environment: {}
PhantomJS is launching GhostDriver...
[INFO - 2016-05-10T09:13:58.925Z] GhostDriver - Main - running on port 19084
[INFO - 2016-05-10T09:13:59.117Z] Session [8784a390-168f-11e6-bcd7-a7a5f8e205b1] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.7 Safari/534.34","webSecurityEnabled":true}
[INFO - 2016-05-10T09:13:59.117Z] Session [8784a390-168f-11e6-bcd7-a7a5f8e205b1] - page.customHeaders: - {}
[INFO - 2016-05-10T09:13:59.117Z] Session [8784a390-168f-11e6-bcd7-a7a5f8e205b1] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"1.9.7","driverName":"ghostdriver","driverVersion":"1.1.0","platform":"mac-unknown-32bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
[INFO - 2016-05-10T09:13:59.117Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 8784a390-168f-11e6-bcd7-a7a5f8e205b1
Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: MAC
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'xxxxxxx', ip: 'xxxxx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: 'xxxxx', java.version: '1.8.0_66'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.internal.Executable.<init>(Executable.java:75)
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:60)
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:56)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
....
My build.gradle:
import org.apache.tools.ant.taskdefs.condition.Os
// set the dependencies for running the groovy script
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.codehaus.groovy:groovy-all:latest.release'
}
}
plugins {
id 'groovy'
}
apply from: "osSpecificDownloads.gradle"
// set the dependencies for compiling the groovy script
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:latest.release'
compile 'org.codehaus.geb:geb-core:latest.release'
compile 'org.seleniumhq.selenium:selenium-firefox-driver:2.53.0'
compile('com.codeborne:phantomjsdriver:1.3.0') {
transitive = false
}
}
// tell gradle the groovy script is in the same folder as the build.gradle file
sourceSets {
main {
groovy {
srcDirs = ['.']
}
}
}
Properties props = new Properties()
props.load(new FileInputStream("$projectDir/../../connection.properties"))
task("CheckHomePhantomJS", type: JavaExec) {
dependsOn unzipPhantomJs
def phantomJsFilename = Os.isFamily(Os.FAMILY_WINDOWS) ? "phantomjs.exe" : "bin/phantomjs"
environment 'phantomjspath', new File(unzipPhantomJs.outputs.files.singleFile, phantomJsFilename).absolutePath
environment 'driver', 'phantomjs'
environment 'gateway', props.gateway
environment 'username', props.username
environment 'password', props.password
main = 'CheckHome'
classpath = sourceSets.main.runtimeClasspath
}
Any idea what is going wrong here?

Geb creates a new Browser instance when you call.
Browser drive(Closure script)
Instead try with
Browser drive(Browser browser, Closure script)
So change your code to
Browser.drive(browser) {
go BiHome
// code omitted for brevity
}

Related

Unable to create Appuim driver session despite having latest chrome driver and slf4j dependencies

I have the latest chrome driver installed, which fixed the issue for others that have encountered the same error. I am new to using Appium.
here is the error:
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 404. Message: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
Host info: host: 'MallSoft.local', ip: '2601:1c2:0:3680:0:0:0:8406%en0'
Build info: version: '4.8.1', revision: '8ebccac989'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '1.8.0_301'
Driver info: io.appium.java_client.android.AndroidDriver
Command: [null, newSession {capabilities=[{appium:app=/Users/fieldemployee/IdeaProjects/FirstAppiumProject/src/main/resources/ApiDemos-debug.apk, appium:automationName=uiAutomator2, appium:deviceName=nexus_5, platformName=ANDROID, appium:udid=emulator-5554}], desiredCapabilities=Capabilities {app: /Users/fieldemployee/IdeaPr..., automationName: uiAutomator2, deviceName: nexus_5, platformName: ANDROID, udid: emulator-5554}}]
Capabilities {app: /Users/fieldemployee/IdeaPr..., automationName: uiAutomator2, deviceName: nexus_5, platformName: ANDROID, udid: emulator-5554}
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:148)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:133)
at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:102)
at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:194)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:262)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:229)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:80)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:92)
at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:117)
at CreateDriverSession.main(CreateDriverSession.java:25)
Process finished with exit code 1
here is my code in IntelliJ:
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
public class CreateDriverSession {
public static void main(String[] args) throws MalformedURLException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "nexus_5");
caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiAutomator2");
caps.setCapability(MobileCapabilityType.UDID, "emulator-5554");
//for windows users
String appUrl = "/Users/fieldemployee/IdeaProjects/FirstAppiumProject/src/main/resources/ApiDemos-debug.apk";
//System.getProperty("user.dir") + File.separator + "src" + File.separator + "main"
//+ File.separator + "resources" + File.separator + "ApiDemos-debug.apk";
caps.setCapability(MobileCapabilityType.APP, appUrl);
URL url = new URL("http://0.0.0.0:4723/");
AppiumDriver driver = new AndroidDriver(url, caps);
}
}
here is the result in the Appium GUI:
[HTTP] No route found for /wd/hud/session
[HTTP] <-- POST /wd/hud/session 404 8 ms - 211
[HTTP]
[HTTP] Request idempotency key: e718b60f-1d53-4e4b-8ebb-ddaf41d23b43
[HTTP] --> POST /session
[HTTP] {"capabilities":{"firstMatch":[{}],"alwaysMatch":{"appium:app":"/Users/fieldemployee/IdeaProjects/FirstAppiumProject/src/main/resources/ApiDemos-debug.apk","appium:automationName":"uiAutomator2","appium:deviceName":"nexus_5","appium:udid":"emulator-5554","platformName":"android"}}}
As stated, I have the latest chrome driver and browser installed (latest as of the date on this post). My initial error was related to slf4j but adding the dependencies to pom resolved it. I have tried changing the url and removing the "/wd/hud/" as well.
Possibly you need to add /wd/hub at the end.
Solution
Instead of:
URL url = new URL("http://0.0.0.0:4723/");
you need to use:
URL url = new URL("http://localhost:4723/");
or
URL url = new URL("http:///127.0.0.1:4723/");
References
You can find a relevant detailed discussion in:
SessionNotCreatedException: Could not start a new session. Unable to parse remote response error using SeleniumGrid

Cargo Tomcat 7.X not stopping

Here is my configuration in gradle file for cargo.
cargo {
containerId = 'tomcat7x'
port = httpPort.toInteger()
local {
homeDir = file(cargoHome)
configHomeDir = file(cargoHome)
jvmArgs = 'Dcom.sun.management.jmxremote.port=9092
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -'
installer {
installUrl = 'https://installdirectory/content/groups/public/org/apache/tomcat/tomcat/7.0.57/tomcat-7.0.57.zip'
downloadDir = file("$buildDir/download")
extractDir = file("$buildDir/extract")
}
containerProperties { property 'cargo.tomcat.ajp.port', portFinder.nextAvailable}
extraClasspath = files("../service/service-1.0.0-LOCAL-local.jar",configurations.cargoruntime) }}
Following error it's shows in log while running cargoStopLocal task
WARNING: StandardServer.await: Invalid command '' received
Error: Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: 9092; nested exception is:
java.net.BindException: Address already in use: JVM_Bind
Nov 20, 2015 4:32:34 PM org.apache.catalina.core.StandardServer await
WARNING: StandardServer.await: Invalid command '' received
can anyone guide me how to handle this issue , it's not stopping cargo server so my build is failing?

Grails: SQLException: No suitable driver found for jdbc:oracle:thin

When I run my app in GGTS 3.6.2 using Grails 2.4.3 I've got a message:
Caused by SQLException: No suitable driver found for jdbc:oracle:thin:#server:port/OCI
->> 689 | getConnection in java.sql.DriverManager
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 247 | getConnection in ''
| 18 | <init> . in awtool.Controller
| 266 | run in java.util.concurrent.FutureTask
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . in java.lang.Thread
Error |
Forked Grails VM exited with errorJava HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
I read many posts about this error and used some recommendations.
I added ojdbc6.jar to project /lib
also I added ojdbc6.jar at project Java Build Path using Add External JAR..
Java and Grails PATHs is OK
Is there is a way how I can resolve this problem ?
BuildConfig.groovy:
grails.servlet.version = "3.0" // Change depending on target container compliance (2.5 or 3.0)
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.work.dir = "target/work"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
//grails.project.war.file = "target/${appName}-${appVersion}.war"
grails.project.fork = [
// configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required
compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
// configure settings for the test-app JVM, uses the daemon by default
// test: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
// configure settings for the run-app JVM
run: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
// configure settings for the run-war JVM
war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
// configure settings for the Console UI JVM
console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
]
grails.project.dependency.resolver = "maven" // or ivymaven
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// specify dependency exclusions here; for example, uncomment this to disable ehcache:
// excludes 'ehcache'
}
log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve
legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility
repositories {
inherits true // Whether to inherit repository definitions from plugins
grailsPlugins()
grailsHome()
mavenLocal()
grailsCentral()
mavenCentral()
// uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories
// mavenRepo "http://repository.codehaus.org"
// mavenRepo "http://download.java.net/maven/2/"
// mavenRepo "http://repository.jboss.com/maven2/"
mavenRepo "http://repo.spring.io/milestone/"
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
runtime 'mysql:mysql-connector-java:5.1.34'
// runtime "com.oracle:ojdbc6:11.2.0.4"
// runtime 'org.postgresql:postgresql:9.3-1101-jdbc41'
test "org.grails:grails-datastore-test-support:1.0-grails-2.4"
}
plugins {
// plugins for the build system only
build ":tomcat:7.0.55"
// plugins for the compile step
compile ":scaffolding:2.1.2"
compile ':cache:1.1.7'
compile ":asset-pipeline:1.9.6"
compile ":spring-security-core:2.0-RC4"
compile ":spring-security-ldap:2.0-RC2"
compile ":force-ssl:1.0.0"
// plugins needed at runtime but not for compilation
runtime ":hibernate4:4.3.5.5" // or ":hibernate:3.6.10.17"
runtime ":database-migration:1.4.0"
runtime ":jquery:1.11.1"
// Uncomment these to enable additional asset-pipeline capabilities
//compile ":sass-asset-pipeline:1.9.0"
//compile ":less-asset-pipeline:1.10.0"
//compile ":coffee-asset-pipeline:1.8.0"
//compile ":handlebars-asset-pipeline:1.3.0.3"
}
}
grails.server.port.http=8088
DataSource.groovy
import groovy.sql.*
dataSource {
pooled = true
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
driverClassName = "com.mysql.jdbc.Driver"
username = "login"
password = "pass"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:mysql://server:port/login"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://server:port/login"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://server:port/login"
}
}
}
"Add External JAR.." and other ways of adding to the IDE classpath aren't useful when using Grails - the IDEs build their classpaths from the Grails dependencies, so you only need to ensure that Grails has access.
When adding jars to the lib dir (which should be avoided in general, but is needed in this case because Oracle annoyingly refuses to put their driver jars in public repos) you need to run
grails compile --refresh-dependencies
to get it added to the classpath - Grails hasn't had auto-detection of jars in /lib for a while.
Once you do that, if you need the jar for compilation (you don't in this case) then refresh the IDE from Grails. In GGTS/STS you can do this by right-clicking the project root node in the tree on the left and selecting Grails Tools | Refresh Dependencies.
In addition to Burt's answer explaining how to get Grails to find your Oracle library, you need to change DataSource.groovy to connect to an Oracle database (it's currently configured for MySQL). You need to change it to something like:
dataSource {
pooled = true
driverClassName = "oracle.jdbc.driver.OracleDriver"
dialect = "org.hibernate.dialect.Oracle10gDialect"
dbCreate = "update"
url = 'jdbc:oracle:thin:#localhost:1521:mydb'
username = "root"
password = "password"
properties {
// See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
jmxEnabled = false
initialSize = 5
maxActive = 50
minIdle = 5
maxIdle = 25
maxWait = 10000
maxAge = 10 * 60000
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
validationQuery = "select 1 from dual"
validationQueryTimeout = 3
validationInterval = 15000
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
jdbcInterceptors = "ConnectionState;StatementCache(max=200)"
defaultTransactionIsolation = Connection.TRANSACTION_READ_COMMITTED
}
}
hibernate {
flush.mode = 'manual'
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.region.factory_class = "net.sf.ehcache.hibernate.EhCacheRegionFactory"
}
Replace mydb, root, and password with the name of your schema, and the username and password you'll use to access it.

OSGi bundle installation using pax-exam issue

I'm trying to write spock pax exam extension, but figured out a problem with bundle installation using server mode.
Here is my code
void visitSpecAnnotation(RunPax annotation, SpecInfo sp) {
sp.addListener(new AbstractRunListener() {
private TestContainer container
#Override
void beforeSpec(SpecInfo spec) {
ExamSystem system = PaxExamRuntime.createServerSystem(
CoreOptions.options(
karafDistributionConfiguration("mvn:org.apache.servicemix/apache-servicemix/4.4.1-fuse-03-06/tar.gz", // artifact to unpack and use
"servicemix", // name; display only
"2.2.4")
.unpackDirectory(new File("target/paxexam/unpack/"))
.useDeployFolder(false),
//debugConfiguration("5005", true),
keepRuntimeFolder(),
configureConsole().ignoreLocalConsole(),
when(isEquinox()).useOptions(
editConfigurationFilePut(
KARAF_FRAMEWORK, "equinox"),
systemProperty("pax.exam.framework").value(
System.getProperty("pax.exam.framework")),
//systemProperty("osgi.console").value("6666"),
//systemProperty("osgi.console.enable.builtin").value("true")
),
logLevel(WARN),
mavenBundle("org.sdo.coding", "words", "1.0")
))
container = PaxExamRuntime.createContainer(system)
container.start()
Thread.sleep(100000)
def ant = new AntBuilder()
ant.sshexec(host: "localhost",
port: '8101',
username: "smx",
password: 'smx',
trust: "yes",
command: "list",
outputproperty: 'result',
knownhosts: '/dev/null')
def result = ant.project.properties.'result'
println "result is $result"
def installed = result =~ /(?m)^(.*Installed.*)$/
println "installed ${installed[0]}"
}
Even if i increase delay i cannot find my bundle installed. I can see that the option mavenBundle doesn't affect karaf start, because if i place wrong version or artifactId, pax won't notify me about it.
Anyone has any clue on this problem?

Geb Firefox Driver: why my test runs twice?

Sorry for all this code, but I don't have a clue what's making my issue, so here it goes.
I configured the geb plugin to run functional tests with JUnit. So I have in my buildConfig.groovy:
def seleniumVersion = "2.29.0"
def gebVersion = "0.7.0"
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
// runtime 'mysql:mysql-connector-java:5.1.5'
provided('com.oracle:oracle:11.1.0.7.0')
provided('com.oracle:i18n:10.2.0.5')
test ("org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion") {
export = false
}
test("org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"){
excludes "commons-io"
export = false
}
test ("org.seleniumhq.selenium:selenium-ie-driver:$seleniumVersion") {
export = false
}
test ("org.seleniumhq.selenium:selenium-support:$seleniumVersion") {
export = false
}
test ("org.seleniumhq.selenium:selenium-remote-driver:$seleniumVersion") {
export = false
}
test ("org.codehaus.geb:geb-junit4:$gebVersion") {
export = false
}
}
plugins {
build(":tomcat:$grailsVersion") {
export = false
excludes 'svn'
}
compile (":hibernate:$grailsVersion") {
export = false
excludes 'svn'
}
build (":release:2.0.0") {
excludes 'commons-io','http-builder'
export = false
}
compile(":spring-security-core:1.2.7.3") { excludes 'svn' }
compile(":spring-security-ldap:1.0.6")
compile (":remote-control:1.3") {
export = false
}
test(":geb:$gebVersion") {
export = false
}
}
And I have a GebConfig.groovy in my conf folder:
driver = {
//def driver = new HtmlUnitDriver()
//driver.javascriptEnabled = true
//driver
def driver = new FirefoxDriver()
driver
}
environments {
// run as “grails -Dgeb.env=chrome test-app”
// See: http://code.google.com/p/selenium/wiki/ChromeDriver
chrome {
driver = { new ChromeDriver() }
}
// run as “grails -Dgeb.env=firefox test-app”
// See: http://code.google.com/p/selenium/wiki/FirefoxDriver
firefox {
driver = { new FirefoxDriver() }
}
}
I have a functional test for the login:
class LoginTests extends GebReportingTest {
#Test
void login() {
to LoginPage
at LoginPage
username = "SERGIO"
password = "SERGIO"
loginButton.click()
assert at(IndexPage)
link.click()
}
}
And this are my two pages:
class LoginPage extends Page {
static url = "login/auth"
static at = {
title ==~ /Efetuar Login/
}
static content = {
loginForm { $("form", id: "loginForm") }
username { $("input", type:"text", id:"username") }
password { $("input", type:"password", id:"password") }
loginButton{ $("input", type:"submit", id:"submit") }
}
}
class IndexPage extends Page {
static at = {
title ==~ /Security Service Index View/
}
static content = {
description { $('h1') }
link { $('a') }
}
}
For some reason my functional test run twice and don't matter how I start this:
grails test-app :functional
grails test-app -functional
It looks like the Geb plugin isn't fully compatible with Grails 2.3.x . For some reason tests get executed twice after upgrading to Geb plugin 0.9.2 .
I believe this problem is related to https://jira.grails.org/browse/GRAILS-10552 and changes made as part of https://jira.grails.org/browse/GRAILS-6352 .
In Grails 2.3.x+, the GrailsSpecTestType takes care of both Junit and Spock tests:
https://github.com/grails/grails-core/blob/bce298f0/grails-test/src/main/groovy/org/codehaus/groovy/grails/test/spock/GrailsSpecTestType.groovy#L33
It looks like the Geb plugin is adding the deprecated JUnit4GrailsTestType to execution:
https://github.com/geb/geb/blob/584738cb/integration/geb-grails/scripts/_Events.groovy#L60-L67
This is why functional tests get executed twice.
This is how I got around the problem in Geb 0.9.2 / 0.9.3 versions.
grails test-app functional:spock
It looks like Geb version 0.9.1 didn't execute the tests twice.
The difference seems to be caused by this commit:
https://github.com/geb/geb/commit/9c71e820
You should also be aware that you shouldn't have the Spock plugin installed in Grails 2.3.x/2.4.x .
Hi Not Much of a Selenium WebDriver on Ruby but It seems to be that you are starting Firefox twice as such the test runs in two instances

Resources