简体   繁体   English

使用 Cucumber 与 Java Selenium 和 Gradle 并行运行测试

[英]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 正确并行运行。

  • 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 logging 需要记录正确的线程和场景

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 scenarioHooks.java 这里有一个我们如何记录线程及其当前场景的例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Cucumber 与 Junit 和 Gradle 并行测试? - Cucumber tests in parallel with Junit and Gradle? 使用gradle并行运行JUnit4测试 - Run JUnit4 tests parallel using gradle 使用Maven Surefire进行并行Cucumber-JVM Selenium网格测试 - Parallel Cucumber-JVM Selenium Grid Tests using Maven Surefire 如何使用Gradle并行运行黄瓜jvm测试场景? - How to run cucumber jvm test scenarios in parallel using Gradle? 无法使用 TestNG 和 SpringBootTest 并行运行 Cucumber 测试 - Cant run Cucumber tests in parallel using TestNG and SpringBootTest Java - 页面工厂 - Selenium - Cucumber:无法运行测试 - Java - Page Factory - Selenium - Cucumber: Impossible to Run Tests 如何实例化远程Web驱动程序,以便我可以在Java和Selenium中通过Serenity并行运行测试 - How to instantiate Remote Web Driver so I can run tests in parallel using Java and Selenium with Serenity 无法在Cucumber&Testng中运行并行测试 - Unable to run parallel tests in Cucumber &Testng Selenium - TestNG:测试未并行运行 - 使用 selenium + java + browserstack - Selenium - TestNG: Tests are not running in parallel - Using selenium + java + browserstack 无法使用TestNG,Gradle和Android Studio并行运行测试 - Unable to run tests in parallel using TestNG, gradle and android studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM