1

I have gradle.properties file for which I am passing value from command line as below command but not taking the value.

gradle test -DsystemProp.RunnerApplication=QAEnv -Dgroups=CSP-Smoke

My build.gradle file code as follows-

import java.util.concurrent.TimeUnit
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
        classpath group: 'org.testng', name: 'testng', version: '6.8.+'
    }
}
plugins {
    id 'java'
}
apply plugin: 'java'
group 'org.csp.xxxx'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
    mavenCentral()
}

test {

    systemProperty "RunnerApplication",System.getProperty("RunnerApplication")

    reports {
        junitXml.enabled = true
        html.enabled = true
        reports.junitXml.destination = file("test-output/reports/")
    }
    def Coregroups = System.getProperty('groups','Core-Smoke \n CSP-Smoke')
    useTestNG()
            {
                includeGroups Coregroups
                useDefaultListeners = true
                options.suites("src/test/java/TestAPISuite.xml")
                //options.listeners << 'com.ddddd.smsApi.qa.framework.listener.CustomListener'
                //options.listeners << 'com.dddd.smsApi.qa.framework.listener.EmailListener'
                options.listeners << 'org.uncommons.reportng.HTMLReporter'
                options.listeners << 'org.uncommons.reportng.JUnitXMLReporter'
                systemProperty 'org.uncommons.reportng.title', 'csp_api_automation_results'
            }
    testLogging.events "passed", "skipped", "failed"
    testLogging.exceptionFormat = "full"
    //Interceptors
    beforeTest { desc ->
        println "\n*** Starting execution of test ${desc.className}.${desc.name} ***"
    }
    afterTest { descriptor, result ->
        println "<<< Test ${descriptor.name} resulted in ${result.resultType} and took "+getElaspedTime(result.endTime - result.startTime)+" >>>\n"
    }
    //Modify the test logging
    testLogging {
        showStandardStreams = true
        exceptionFormat "full"
    }
}
sourceSets {
    main {
        runtimeClasspath = files(output.resourcesDir) + runtimeClasspath
    }
    test {
        runtimeClasspath = files(output.resourcesDir) + runtimeClasspath
    }
}
dependencies {
    compile group: 'io.rest-assured', name: 'rest-assured', version: '3.0.2'
    testCompile group: 'org.testng', name: 'testng', version: '6.8.+'
    //An assertion library that is better than JUnit defaults
    testCompile 'org.easytesting:fest-assert-core:2.0M10'
    //Better reporting for testng.  It outputs a nice html report
    testCompile 'org.uncommons:reportng:1.1.4'
    compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.15'
    compile group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'
    compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
    compile group: 'com.googlecode.htmlcompressor', name: 'htmlcompressor', version: '1.5.2'
    compile group: 'commons-dbutils', name: 'commons-dbutils', version: '1.6'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.6'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.6'
    compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.5'
    compile group: "com.github.fge", name: "json-schema-validator", version: "2.2.6"
    compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
    compile group: 'org.json', name: 'json', version: '20160810'
    compile group: 'org.uncommons', name: 'reportng', version: '1.1.4'
    compile group: 'com.google.code.guice-repository', name: 'guice-repository', version: '2.1.0'
    compile group: 'org.easytesting', name: 'fest-assert-core', version: '2.0M10'
    compile group: 'org.uncommons', name: 'reportng', version: '1.1.4'
    compile group: 'org.apache.commons', name: 'commons-csv', version: '1.5'
    compile group: 'org.apache.commons', name: 'commons-exec', version: '1.3'
    compile group: 'com.opencsv', name: 'opencsv', version: '4.1'
    compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'
    compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.1'
    compile group: 'com.sun.mail', name: 'javax.mail', version: '1.6.0'
    compile group: 'javax.mail', name: 'javax.mail-api', version: '1.6.2'
    compileClasspath group: 'org.testng', name: 'testng', version: '6.8.+'
    // https://mvnrepository.com/artifact/com.cedarsoftware/json-io
    compile group: 'com.cedarsoftware', name: 'json-io', version: '2.6.0'
    // https://mvnrepository.com/artifact/org.apache.poi/poi
    compile group: 'org.apache.poi', name: 'poi', version: '3.17'
    // https://mvnrepository.com/artifact/com.aventstack/extentreports
    compile group: 'com.aventstack', name: 'extentreports', version: '4.0.9'
}
def getElaspedTime(def time) {
    if(time / 1000 < 1)
    {
        return String.format("0 min, %.3f sec", time/1000)
    }
    else
    {
        return String.format("%d min, %d sec",
                TimeUnit.MILLISECONDS.toMinutes(time),
                TimeUnit.MILLISECONDS.toSeconds(time) -
                        TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))
        )
    }
}

systemProp.RunnerApplication=dev is the key and value saved in my gradle.properties. Here I want to run as RunnerApplication=QAEnv so automation can run in different environments

But its is always running on dev even Passing QAEnv in command line.

I would really appreciate your help.

Sobhit Sharma
  • 697
  • 14
  • 45
  • Did you get any solutions for your problems ? As i am also new to gradle and trying many ways to find the solution for my problems. – Balaji Singh .Y Sep 05 '20 at 19:10
  • Can you get connected on gmail to discuss further : baluzen@gmail.com mobile : 8884479958 – Balaji Singh .Y Sep 05 '20 at 19:11
  • Yes, I have fixed this issue. Do you have a connection link? – Sobhit Sharma Sep 06 '20 at 10:42
  • No dont have a link. Can you please share the same and if provided please discuss the same through call also. – Balaji Singh .Y Sep 06 '20 at 11:01
  • Can you please also tell me how to just execute/run the cucumber runner file through gradle build as we do normally with maven or we just do like usually run the TestNGCucumberRunner.java in IntelliJ /eclipse by right-click and it runs successfully. My intent is to Invoke the TestNGCucumberRunner.java in gradle and Invoke all the features in gradle and at the end reports generated – Balaji Singh .Y Sep 06 '20 at 11:06
  • Please create a question so I can answer on it. Please share the question link here. – Sobhit Sharma Sep 06 '20 at 11:39
  • https://stackoverflow.com/questions/63745230/i-need-to-have-an-gradle-task-to-execute-my-cucumber-runner-class-and-execute-cu – Balaji Singh .Y Sep 06 '20 at 13:37
  • : https://stackoverflow.com/questions/63745365/how-could-i-create-a-gradle-task-to-perform-logging-using-log4j – Balaji Singh .Y Sep 06 '20 at 13:39
  • I need to invoke Cucumber Runner through gradle and which in turn does all the test execution and reporting also https://stackoverflow.com/questions/63765077/i-need-to-invoke-cucumber-runner-through-gradle-and-which-in-turn-does-all-the-t – Balaji Singh .Y Sep 06 '20 at 14:16
  • Any update on the above queston – Balaji Singh .Y Sep 07 '20 at 11:48
  • @BalajiSingh.Y I have answered to your question Link. Please check and let me know if it works – Sobhit Sharma Sep 09 '20 at 11:33

1 Answers1

0

You are passing in two system properties. One is prefixed with systemProp. and the other isn't. This should indicate to you that one of them is wrong. And it's the former :)

There is a use for the systemProp. prefix, but only when declaring system properties through the gradle.properties file. Here, you are declaring them from the command line.

So instead of:

gradle test -DsystemProp.RunnerApplication=QAEnv -Dgroups=CSP-Smoke

Run:

gradle test -DRunnerApplication=QAEnv -Dgroups=CSP-Smoke

Bjørn Vester
  • 6,851
  • 1
  • 20
  • 20
  • I used gradle test -DRunnerApplication=QAEnv -Dgroups=CSP-Smoke, didnt work. Still runs on dev instead of QAEnv. Also gradle.properties contains- systemProp.RunnerApplication=dev – Sobhit Sharma Dec 06 '19 at 06:04