Parallel execution of TestNG suites with different browser combinations

I am new to Gradle 1.4. I have a requirement to Automate the Test cases across different Browser combination which I need to run on sauce labs.I have used Selenium 2.31 and TestNG for building the scripts. I am passing the browser and platform combinations from build.gradle as System Property and within the script I am instantiating the browser on sauce labs.

ext.exeenvironments = [“RemoteWin2008firefox18”, “RemoteWin2008Gchrome24”] //smoke Test Automation tasks GParsPool.withPool(poolSize) {

exeenvironments.eachParallel { environment ->

task “${environment}Test”(type: Test) {

systemProperty “LOG_DIRECTORY”,"$buildDir/reports/tests/"

testReportDir = file("$buildDir/reports/tests/AutomationTest-report")

systemProperty “exeenvironment”, environment

useTestNG()

options.suites(“src/test/resources/nike/Wholesale/testng.xml”)

}}}

task smokeTest(overwrite: true,dependsOn: exeenvironments.collect {tasks["${it}Test"]})

The values present in exeenvironment are userdefinednames which I will split inside the selenium script to identify the platform,browser and version combinations.

Now, I want the test present in my TestNG suite to run parallel across the mentioned browsers. But the scripts are executed successfully in sequential manner but not parallel. I have also tried with maxParallelForks also but that doesn’t work.

Kindly let me know how I can run my TestNG suite with all the different browser combinations.

So you want to run the same test suite multiple times in parallel, with varying configuration? Gradle itself doesn’t currently provide a straightforward way to do this. Since you are using TestNG, I’d check if TestNG’s parallelization and configuration features can deal with this.

PS: Parallelizing evaluation of the build script is the wrong approach and won’t affect test execution at all.

You have four options for parallelism:

  1. Build invocation parallelism by CI server - e.g. multiple build jobs

  2. Parallel Gradle task execution - http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:parallel_execution 3. Parallel test execution - http://www.gradle.org/docs/current/userguide/java_plugin.html#N125A8 4. TestNG parallelism

The simplest solution is usually to use a combination of #1 and #3.

The caveat with #2 is that Gradle only parallelises tasks in different projects. The caveat with #4 is that all of your test setup/config code (e.g. creating your WebDriver instances) must be thread safe.