Run tests in parallel using Cucumber with Java Selenium with Gradle

痴心易碎 提交于 2021-01-28 06:20:31

问题


I'm using Cucumber with Gradle and would like to run Cucumber features in parallel but can't figure out how. My cucumber executor looks like this:

task cucumber() {
dependsOn assemble, compileTestJava
doLast {
    javaexec {
        main = "cucumber.api.cli.Main"
        classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
        args = ['--plugin', 'pretty',
                '--plugin', 'json:build/reports/cucumber-report.json',
                '--plugin', 'html:build/reports/cucumber-report.html',
                '--glue', 'stepDefinitions',
                'src/test/java']
        systemProperty "cucumber.options", System.getProperty("cucumber.options")
    }
}

}

Thanks, any help is appreciated


回答1:


There is a bit of setup needed to get cucumber running in parallel properly with gradle.

  • Every test has to be threadsafe so you need to be careful with static usage.
  • Multiple drivers need to be made for each thread
  • logging needs to log the correct thread and scenario

I have a skeleton framework that handles all of this that you can use as a reference or build from here

For your specific question in the build.gradle you determine the --threads cucumber option.

Take a look in the build.gradle here

These variables are used to setup parallel runs and determine threads to use in the cucumber options

def availableThreadCount = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
def cucumberThreadsOption = ['--threads', availableThreadCount.toString()]

if runInParallel task is used it puts setParallel to true. We then add the --threads arg into the cucumber options This is where that happens in the cucumber task

Here is where the built cucumber options are used

CreateSharedDrivers.java here is where we handle creating multiple drivers for threads and have the shutdown hook implemented.

In Hooks.java here there is an example of how we log the thread and its current scenario



来源:https://stackoverflow.com/questions/52045421/run-tests-in-parallel-using-cucumber-with-java-selenium-with-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!