[英]Run tests in parallel using Cucumber with Java Selenium with Gradle
I'm using Cucumber with Gradle and would like to run Cucumber features in parallel but can't figure out how.我将 Cucumber 与 Gradle 一起使用,并希望并行运行 Cucumber 功能,但不知道如何操作。 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谢谢,任何帮助表示赞赏
There is a bit of setup needed to get cucumber running in parallel properly with gradle.需要一些设置才能使黄瓜与 gradle 正确并行运行。
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.对于build.gradle中的特定问题,您可以确定--threads cucumber 选项。
Take a look in the build.gradle here 在这里查看 build.gradle
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.如果使用runInParallel任务,它会将setParallel 设置为 true。 We then add the --threads arg into the cucumber options This is where that happens in the cucumber task
然后我们将--threads arg 添加到 cucumber 选项中这是在cucumber任务中发生的地方
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. 此处的 CreateSharedDrivers.java是我们处理为线程创建多个驱动程序并实现关闭挂钩的地方。
In Hooks.java here there is an example of how we log the thread and its current scenario在Hooks.java 这里有一个我们如何记录线程及其当前场景的例子
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.