6

I have the following task

task testGeb(type:Test) {
   jvmArgs '-Dgeb.driver=firefox'
   include "geb/**/*.class"
   testReportDir = new File(testReportDir, "gebtests")
}

The system property doesn't appear to make it to the Geb tests, as Geb does not spawn Firefox to run the tests. When I set the same system property in Eclipse and run the tests, everything works fine.

Ray Nicholus
  • 19,538
  • 14
  • 59
  • 82

5 Answers5

17

Try using system properties:

test {
   systemProperties['geb.driver'] = 'firefox'
   include "geb/**/*.class"
   testReportDir = new File(testReportDir, "gebtests")
}
Nikita Skvortsov
  • 4,768
  • 24
  • 37
  • This might actually be an issue with Geb. I confirmed that the prop is being passed properly. – Ray Nicholus Apr 13 '11 at 20:59
  • There was a bug in early snapshot versions of 0.6 that would have prevented this from working, but it has been resolved for the 0.6 final. – Luke Daley May 30 '11 at 07:43
7

You can also directly set the system property in the task:

task testGeb(type:Test) {
    System.setProperty('geb.driver', 'firefox')}

(the solution above will also work for task type different from Test)

or if you would like to be able to pass different properties from the command line, you can include a more flexible solution in the task definition:

task testGeb(type:Test) {
    jvmArgs project.gradle.startParameter.systemPropertiesArgs.entrySet().collect{"-D${it.key}=${it.value}"}
}

and then you can run: ./gradlew testGeb -D[anyArg]=[anyValue], in your case: ./gradlew testGeb -Dgeb.driver=firefox

OlgaMaciaszek
  • 3,662
  • 1
  • 28
  • 32
1
Below code works fine for me using Gradle and my cucumber scenarios are passing perfectly. Add below code in your build.gradle file:

//noinspection GroovyAssignabilityCheck

test{

    systemProperties['webdriver.chrome.driver'] = '/usr/bin/google_chrome/chromedriver'

}

Note: I used Ubuntu OS and the chrome_driver path I specified in /usr/bin/google_chrome/ and your path varies according to your path.

Madasu
  • 11
  • 1
1

Add systemProperties System.getProperties() in your task

test {
  ignoreFailures = false
  include "geb/**/*.class"
  testReportDir = new File(testReportDir, "gebtests")
  // set a system property for the test JVM(s)
  systemProperties System.getProperties()
}

So that it will be configurable while running the test. For example

gradle -Dgeb.driver=firefox test
gradle -Dgeb.driver=chrome test 
arulraj.net
  • 4,579
  • 3
  • 36
  • 37
0

I would recommend doing the following

gradle myTask -DmyParameter=123

with the following code

task myTask {
    doLast {
        println System.properties['myParameter']
    }
 }

The output should be

gradle myTask -DmyParameter=123 :myTask 123

BUILD SUCCESSFUL

Total time: 2.115 secs

techarch
  • 1,121
  • 2
  • 20
  • 30