Gradle -> TestNg -> How to run TestNg suite from Gradle


(Jagatheswaran) #1

Hi Frnds,

I am new to Gradle and have Gradle project with TestNg script and I need to run my test thorugh gradle,so could you please help me to run.

Please find My Build.gradle

/*

  • This build file was generated by the Gradle ‘init’ task.
  • This generated file contains a sample Java Library project to get you started.
  • For more details take a look at the Java Libraries chapter in the Gradle
  • user guide available at https://docs.gradle.org/3.5/userguide/java_library_plugin.html
    */
    apply plugin: 'java’
    apply plugin: ‘maven’

sourceCompatibility = 1.5
targetCompatibility = 1.5
tasks.withType(JavaCompile) {
options.encoding = ‘UTF-8’
}

repositories {

 maven { url "http://repo.maven.apache.org/maven2" }

}

dependencies {
compile group: ‘org.seleniumhq.selenium’, name: ‘selenium-java’, version:'2.52.0’
compile group: ‘org.seleniumhq.selenium’, name: ‘selenium-server’, version:'2.52.0’
compile group: ‘info.cukes’, name: ‘cucumber-java’, version:'1.2.2’
compile group: ‘info.cukes’, name: ‘cucumber-testng’, version:'1.2.4’
compile group: ‘info.cukes’, name: ‘cucumber-core’, version:'1.2.4’
compile group: ‘org.hamcrest’, name: ‘hamcrest-all’, version:'1.3’
compile group: ‘info.cukes’, name: ‘gherkin’, version:'2.12.2’
compile group: ‘com.google.guava’, name: ‘guava’, version:'18.0’
testCompile group: ‘org.testng’, name: ‘testng’, version:‘6.8’
}

test {
useTestNG() {
useDefaultListeners = true
suites ‘src/test/resources/AllTest.xml’
}
}