Reputation: 2050
I try to use SystemProperties in the testing project, but can't get any in the code.
The CLI command:
gradle uitests -Dbrowser=chrome
Project structure:
my-app/
├─ src/
│ ├─ test/
│ │ ├─ java/
│ │ │ ├─ LoginTest.java
│ │ │ ├─ BaseTest.java
│ │ ├─ resources/
│ │ │ ├─ login.feature
├─build.gradle
tasks.withType(Test){
systemProperty 'browser', System.getProperty('browser')
println systemProperties.get('browser') <------------------------(1)
}
task uitests() {
dependsOn assemble, testClasses
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = [
'--plugin', 'pretty',
'--plugin', 'html:target/cucumber-report.html',
'--glue', myproject.steps',
'src/test/resources/scenarios']
}
}
}
So, line (1) printed the correct parameter that I need, but when I try to get this parameter in the code with System.getProperty("browser");
I get null
Upvotes: 0
Views: 233
Reputation: 2438
because -D JVM param is limited to the gradle JVM only, it will NOT be auto passed to the javaexec
that has been created manually with specific args.
you have add jvmArgs = ['-Dbrowser='+System.getProperty('browser')]
see https://docs.gradle.org/current/dsl/org.gradle.api.tasks.JavaExec.html
Upvotes: 1