Git Product home page Git Product logo

gradle-cucumber-runner's Introduction

Gradle Cucumber runner

A gradle plugin for running Cucumber-JVM.

It utilises the Cucumber-JVM command line implementation and forwards every call to cucumber.api.cli.Main

Usage

Add the plugin to your project

plugins {
  id "se.thinkcode.cucumber-runner" version "0.0.11"
}

The complete, and updated, instructions are availabe at the plugin portal.

Then run Cucumber with the default settings

./gradlew cucumber

Configuration

Cucumber must know where your steps are implemented. Add an extension to your gradle build script.

cucumber {
    glue = 'classpath:se.thinkcode'
}

This will search for steps in the package se.thinkcode and any subpackages below it.

The complete list of options that can be set are these:

cucumber {
    threads = '4'
    glue = 'classpath:se.thinkcode'
    extraGlues = ['another.classpath', 'to.include']
    plugin = ['pretty']
    tags = ''
    name = ''
    dryRun = 'true'
    monochrome = 'please'
    strict = 'please'
    snippets = ''
    version = ''
    help = ''
    i18n = ''
    wip = ''
    shorten = ''

    featurePath = 'src/test/resources'
    main = 'cucumber.api.cli.Main'
}

The only setting with default values are

    featurePath = 'src/test/resources'
    main = 'cucumber.api.cli.Main'

Options

The options available can be listed with the command

./gradlew help --task cucumber

Single word options can be given to Cucumber with the syntax

./gradlew cucumber --i18n help

More complicated expressions should be quoted to be forwarded to Cucumber.

./gradlew cucumber --tags "not @wip"

Tags

An important part of running Cucumber is to be able to partition the execution using different tags.

Executing a single tag can be done like this:

./gradlew cucumber --tags @wip

(assuming that you have a tag for work in progress, wip)

Cucumber supports multiple tags to be executed at the same time. Or negating a tag so everything else is executed. Unfortunately, you can't stack tags. The solution is to put them into quotes like this:

./gradlew cucumber --tags "not @wip"

Doing so will forward the expression not @wip to the option -tags and finally to Cucumber.

Glues

Cucumber uses glue to locate where the step definitions are.

Specify them in the build file using glue as a string if you use one path and extraGlues as an array of strings if you need more than one path

glue = 'classpath:se.thinkcode'
extraGlues = ['another.classpath', 'to.include']

Or specify them as a command line option:

--glue "classpath:se.thinkcode"

OR

--glue "classpath:se.thinkcode, another.classpath, to.include"
# The string will be divided into an array with `,` as delimiter. Any whitespace around `,` will be removed. 

Plugins

Cucumber supports usage of multiple plugins at the same time.

Specify them as an array of strings in the build file

plugin = ['se.thinkcode.progress.ProgressPrinter', 'se.thinkcode.report.MultiSeamHtmlReport:./build/reports']

Or specify them as a command line option:

--plugin "se.thinkcode.progress.ProgressPrinter, se.thinkcode.report.MultiSeamHtmlReport:./build/reports"

The string will be divided into an array with , as delimiter. Any whitespace around , will be removed.

This will specify that two plugins will be used and there names are

  • se.thinkcode.progress.ProgressPrinter
  • se.thinkcode.report.MultiSeamHtmlReport:./build/reports

The se.thinkcode.report.MultiSeamHtmlReport:./build/reports plugin will be configured to use the directory ./build/reports.

Running features in parallel

Cucumber supports parallel execution if you specify the number of thread to use. This can be done in two ways

  • An option whn running from a command line, ./gradlew cucumber --threads 4, this will run four parallel threads
  • An extension, that is setting the value in your build.gradle file in the cucumber section.

When setting the value in the build script, you can't really know how many threads the build will have access to. Hardcoding a fixed number may not be your best option.

One way of specifying the number of threads to use is:

cucumber {
    threads = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
}

This will use as many threads as possible while leaving resources for Gradle to execute.

Shortening the command line

To solve the issue on Windows where there is a command line's length limit, use the option --shorten. The plugin will shorten the command line by making a temporary file for the classpath

you can specify them in the build file like this:

cucumber {
    shorten = manifest
}

or via the command line:

--shorten manifest

there are two possible values:

  • manifest, using a temporary manifest jar file to supply the classpath
  • argfile, using @argFile to supply the classpath (Java 9+)

--junit

Cucumber support setting properties for junit from the command line. The option --junit is not supported.

If you have an example where you think you need it, please share the example nd the desired outcome. Maybe there should be support for --junit. If that is the case, it is possible that it will be implemented.

Getting help

./gradlew cucumber --cucumber-help=please

This will call Cucumber with the argument --help. Unfortunately, Gradle requires that each command line option is followed by a value. It is please above. However, it could be anything.

Trouble shooting

Java 8 is required

The plugin is build using Java 8 and gradle must be executed with Java 8 or newer.

The cucumber command executed

Execute Gradle with debug to see the command that will be executed.

The printout is verbose, search for Cucumber command to find the actual command executed.

Caveat

In order for Cucumber to have all test resources available, the cucumber task depends on the java plugin task check. This means that your unit tests will be executed before Cucumber is executed.

The Java plugin lifecycle is described in the Java plugin documentation.

Development

Development is described in development.md

gradle-cucumber-runner's People

Contributors

keychera avatar tsundberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gradle-cucumber-runner's Issues

Debugging: Breakpoints are not hit in IntellijIDEA

Hi, I am trying to run tests by using that runner. And what I am facing is that in debug mode IntellijIdea doesn't hit the breakpoints in step definition files. In case if I am running tests via Cucumber-Java Run Configuration all breakpoints are hit. Do you have any insights on why it can happen? Thank you.

Add parent sourceSet

Currently I'm using commercehub-oss/gradle-cucumber-jvm-plugin. Unfortunately it is unmaintained and does not support Gradle6+. I forked it, fixed and published, but I'm still waiting for an approval.

gradle-cucumber-jvm-plugin has nice feature - it can create source set automatically and use it to run cucumber tests. This way cucumber tests are separated from unit tests. I can add source set manually but I can't use it with your plugin.

Can you add new parameter, something like parentSourceSet in the extension? Then change sourceSet lookup in CucumberTask:

for (SourceSet sourceSet : sourceSets) {
    if (extension.parentSourceSet.equals(sourceSet.getName())) {
        return sourceSet.getRuntimeClasspath().getAsPath();
    }
}

or using streams:

  private String getClasspath() {
    SourceSetContainer sourceSets = getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();

    return sourceSets.stream()
        .filter(sourceSet -> sourceSet.getName().equals(extension.parentSourceSet)).findFirst()
        .map(sourceSet -> sourceSet.getRuntimeClasspath().getAsPath())
        .orElseThrow(() -> {
              throw new RuntimeException("The test classpath was not found");
            }
        );
  }

Do you accept pull requests?

Two windows per thread

When I set threads to 1, I get two windows opened, if two then 4 windows.

`$ gradle cucumber --threads=2

Scenario: Set performance goal # src/test/java/features/performance-goal.feature:9

Scenario: Set regional preference # src/test/java/features/regional-preference.feature:9
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7) on port 44287
Only local connections are allowed.
Starting ChromeDriver 2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7) on port 37689
Only local connections are allowed.
May 01, 2021 7:03:31 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
May 01, 2021 7:03:31 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Found exact CDP implementation for version 90
May 01, 2021 7:03:31 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
May 01, 2021 7:03:31 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Found exact CDP implementation for version 90
I am creating Chrome webdriver for scenario 2
I am creating Chrome webdriver for scenario 2
Starting ChromeDriver 2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7) on port 2535
Only local connections are allowed.
Starting ChromeDriver 2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7) on port 6226
Only local connections are allowed.
May 01, 2021 7:03:40 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
May 01, 2021 7:03:40 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Found exact CDP implementation for version 90
May 01, 2021 7:03:40 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
May 01, 2021 7:03:40 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Found exact CDP implementation for version 90
I am creating Chrome webdriver for scenario 1
I am creating Chrome webdriver for scenario 1
`

java.io.IOException: Cannot run program "java": CreateProcess error=206, The filename or extension is too long

Hi!

I have a build.gradle file with this configuration:

plugins {
    id "se.thinkcode.cucumber-runner" version "0.0.11"
}

cucumber {
    plugin = ['pretty', 'json:target/cucumber/cucumber.json', 'org.citrusframework.cucumber.CitrusReporter']
    glue = 'classpath:com.xy.tccm.integrationtests'
    tags = 'not @ignore'
    extraGlues = ['org.citrusframework.yaks.standard']

    main = 'io.cucumber.core.cli.Main'
    featurePath = 'src/test/resources/features'
}

dependencies {
    testImplementation project(':test-common')
    testImplementation project(':tollcharger-interfaces')

    testImplementation enforcedPlatform('io.cucumber:cucumber-bom:7.15.0')
    testImplementation enforcedPlatform('org.citrusframework:citrus-bom:4.1.0')

    // Cucumber dependencies
    testImplementation 'io.cucumber:cucumber-java'
    testImplementation 'io.cucumber:cucumber-junit'
    testImplementation 'io.cucumber:cucumber-spring'

    // Spring citrus dependencies
    testImplementation 'org.springframework:spring-test:6.1.3'
    testImplementation 'org.springframework.ws:spring-ws-security:4.0.6'

    // Citrus framework
    testImplementation 'org.citrusframework:citrus-base'
    testImplementation 'org.citrusframework:citrus-spring'
    testImplementation 'org.citrusframework:citrus-cucumber'
    testImplementation 'org.citrusframework:citrus-endpoint-catalog'
    testImplementation 'org.citrusframework:citrus-kafka'
    testImplementation 'org.citrusframework:citrus-validation-json'
    testImplementation 'org.citrusframework:citrus-validation-xml'
    testImplementation 'org.citrusframework:citrus-ws'
    testImplementation 'org.citrusframework.yaks:yaks-standard:0.17.1'
    testImplementation 'org.citrusframework.yaks:yaks-steps:0.17.1'
    testImplementation 'org.citrusframework.yaks:yaks-kafka:0.17.1'

    // Junit dependencies
    testImplementation 'org.junit.vintage:junit-vintage-engine:5.10.1'
}

compileJava {
    options.encoding = 'UTF-8'
    options.compilerArgs << '-parameters'
}

compileTestJava {
    options.encoding = 'UTF-8'
}

I also don't have steps config, because I use the predefined yaks steps to run the feature file, but when I try to run the tests using the plugin I get the following error:

Execution failed for task ':integration-tests:cucumber'.
> java.lang.RuntimeException: java.io.IOException: Cannot run program "java": CreateProcess error=206, The filename or extension is too long

What could be the issue?

command line length limit

Hello,
I faced with problem then execute gradle cucumber:
> java.lang.RuntimeException: java.io.IOException: Cannot run program "java": CreateProcess error=206, The filename or extension is too long

It happens then I added some new dependencies to build.gradle file. Is it possible to workaround command line length limit?

Windows 10
(AdoptOpenJDK)(build 1.8.0_242-b08)
Gradle 6.1.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.