使用Cucumber和Java Selenium with Gradle并行运行测试 [英] Run tests in parallel using Cucumber with Java Selenium with Gradle

查看:99
本文介绍了使用Cucumber和Java Selenium with Gradle并行运行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Cucumber与Gradle结合使用,想并行运行Cucumber功能,但不知道如何操作.我的黄瓜执行者是这样的:

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")
    }
}

}

谢谢,感谢您的帮助

推荐答案

要使黄瓜与gradle并行运行,需要进行一些设置.

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

  • 每个测试都必须是线程安全的,因此您在使用静态数据时要格外小心.
  • 每个线程需要制作多个驱动程序
  • 日志记录需要记录正确的线程和方案

我有一个骨架框架可以处理所有这些用作为参考或从此处构建

针对您在 build.gradle 中的特定问题,确定-threads 黄瓜选项.

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

看看在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()]

如果使用 runInParallel 任务,则会将 setParallel 设置为true.然后,我们将-threads arg添加到黄瓜选项中这就是发生在黄瓜任务

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

这是哪里使用内置的黄瓜选项

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

这篇关于使用Cucumber和Java Selenium with Gradle并行运行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆