How to add parameter thread count using existing xml testng suite?

520 views Asked by At

I want to set parameter thread-count in existing suite xml file gradle custom task with type Test. I Want to set useTestNG and after that use TestNG.class for test

String sourceDir = "src"
String resourcesPath = sourceDir.concat("/test/resources")

sourceSets {
test {
    java {
        srcDirs = [sourceDir]
        }
    resources {
        srcDirs = [resourcesPath]
        }
    }
}

apply plugin: 'java'

dependencies {
compile project(':core')
compile group: 'org.testng', name: 'testng', version: '6.1.1'
}

task customTask(type: Test) {

    useTestNG {
        String threads = System.getenv("THREADS")
        String suiteName = System.getenv("SUITE")
        useDefaultListeners = true
        testLogging {
            events "passed", "skipped", "failed"
        }
     }

    //What I trying to do, but i have no acces to testng package

    TestNG tng = new TestNG();
    tng.setXmlSuites(suiteName);
    tng.setThreadCount(threads)
    tng.run(); 
}

So how I add parameter thread count using existing xml testng suite? Do I have create TestNG instance, set suite from existing file and set threadCount? And how I can create suite object from exising xml file?

0

There are 0 answers