How can I pass the properties of the JVM system to my tests?

I have the following task

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

The system property does not seem to fall into the Geb tests, since Geb does not start Firefox to run the tests. When I set the same system property in Eclipse and run the tests, everything works fine.

+5
source share
5 answers

Try using the system properties:

test {
   systemProperties['geb.driver'] = 'firefox'
   include "geb/**/*.class"
   testReportDir = new File(testReportDir, "gebtests")
}
+15
source

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 a task type other than Test)

, :

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

: ./gradlew testGeb -D[anyArg]=[anyValue], : ./gradlew testGeb -Dgeb.driver=firefox

+5
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'

}

. Ubuntu OS chrome_driver, /usr/bin/google _chrome/, .

+1

systemProperties System.getProperties()

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

, .

gradle -Dgeb.driver=firefox test
gradle -Dgeb.driver=chrome test 
+1

gradle myTask -DmyParameter=123

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

gradle myTask -DmyParameter = 123  :  123

: 2.115

0

All Articles