How to pass Gradle command line arguments to Step definition in cucumber?

Viewed 35

I want to access command line arguments provided by gradle in my step definition file. Same like maven mvn test -Dbrowser=firefox and then access in java stepdef file using code

String browser = System.getProperty("browser", "chrome");

My build.gradle file is:

plugins {
    id 'application'
}

repositories {
    mavenCentral()
}

application {
    mainClass = 'ts.api.automation.App'
}

configurations {
    cucumberRuntime {
        extendsFrom testImplementation
    }
}

task cucumber() {
    dependsOn assemble, testClasses
    doLast {
        javaexec {
            main = "io.cucumber.core.cli.Main"
            classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
            args = ['--plugin', 'pretty', '--glue', 'smartconnect.steps.grab', 'src/test/java/smartconnect/features/grab']
        }
    }
}

task runTests(type: JavaExec, dependsOn: 'classes') {
    main = 'org.testng.TestNG'
    classpath = files("./src/test/resources",
            project.sourceSets.main.runtimeClasspath,
            project.sourceSets.test.runtimeClasspath)
    args = ["-parallel",  "methods", "-threadcount", "1", "-d", "./build/test-output", "./src/test/resources/TestNG.xml"]
}

How should I pass arguments to my step def file which are fetch from command line using Gradle?

Probably, I can access it in my base Java class

0 Answers
Related