Passing in tags to Gradle cucumber task

Sunny Patel :

I know that we can pass cucumber tags to Gradle by specifying the following in build.gradle file:

test {
    systemProperty "cucumber.options", System.getProperty("cucumber.options")
}

So when you run gradlew test -Dcucumber.options="--tags @CDC" it will only runs scenarios with CDC tag.

But my question is whether I can pass the cucumber options to the cucumber task. The reason I need to do this is because my cucumber task creates a JSON file after running the task, and I'm using gradle-cucumber-reporting plugin (https://github.com/SpacialCircumstances/gradle-cucumber-reporting) to generate a report based on the JSON file.

cucumber task

task cucumber() {
    dependsOn assemble, compileTestJava
    doLast {
        javaexec {
            main = "io.cucumber.core.cli.Main"
            classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
            args = [
            '--plugin', 'html:cucumber-report',
            '--plugin', 'json:cucumber.json', //generates a .json report file
            '--plugin', 'pretty',
            '--plugin', 'usage:cucumber-usage.json',
            '--glue', 'hellocucumber', 'src/test/resources']
        }
    }
}

Running the test task in Gradle doesn't update the JSON file.

Here's the snippet for gradle-cucumber-reporting:

cucumberReports {
  outputDir = file('cucumber-pretty-report')
  buildId = '0'
  reports = files('cucumber.json')
}
rasklaad :

You can add something like this to your cucumber task:

def tags = getProperty("tags")
args = [
'--plugin', 'html:cucumber-report',
'--plugin', 'json:cucumber.json', //generates a .json report file
'--plugin', 'pretty',
'--plugin', 'usage:cucumber-usage.json',
'--glue', 'hellocucumber', 'src/test/resources',
'--tags', tags]

Then you can run your task this way:

gradle cucumber -P tags=smoke

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Passing parameter to custom Gradle task

分類Dev

Passing folder name to task

分類Dev

Gradle Kotlin、Cucumber、およびOKHttp

分類Dev

Gradle Heroku Task 'stage'

分類Dev

Modify an existing gradle task

分類Dev

Modify an existing gradle task

分類Dev

Visualize gradle task dependencies

分類Dev

Passing arguments to build.gradle

分類Dev

Override Task in build.gradle

分類Dev

Convert ant signJar task to gradle

分類Dev

Is there a way to integrate Gradle / Cucumber / Selenium tests into Browserstack (Java)?

分類Dev

Gradle build: Execution failed for task ':app:lint'

分類Dev

Gradle build: Execution failed for task ':app:lint'

分類Dev

Android - what is gradle task connectedCheck used for

分類Dev

Gradle leftshift << operator with Task needed? (Is it superfluous)

分類Dev

Gradle: custom task with jvm arguments for Spring Boot

分類Dev

Could not get unknown property for task in Gradle?

分類Dev

Run gradle build(test) in subprojects in a custom task

分類Dev

Cannot exclude directories for a Gradle copy task

分類Dev

Gradle: execute tasks sequentially in some task

分類Dev

Use withType() for configuring Gradle task not compiling in IntelliJ

分類Dev

gradle: Skipping task ':compileJava' as it has no source files

分類Dev

Passing Task as parameter to be invoked within loop in async method C#

分類Dev

cucumber.api.Scenarioのgradle依存関係は何ですか

分類Dev

Passing parameters to corb uri stage using ml-gradle

分類Dev

Gradle 5とCucumber-JVMを使用して別のディレクトリからCucumberを実行する

分類Dev

How to execute a task before executing or building the subprojects in gradle?

分類Dev

make gradle dependency task to exclude test dependencies in its result

分類Dev

Android gradle - top level vs module level "build" task

Related 関連記事

  1. 1

    Passing parameter to custom Gradle task

  2. 2

    Passing folder name to task

  3. 3

    Gradle Kotlin、Cucumber、およびOKHttp

  4. 4

    Gradle Heroku Task 'stage'

  5. 5

    Modify an existing gradle task

  6. 6

    Modify an existing gradle task

  7. 7

    Visualize gradle task dependencies

  8. 8

    Passing arguments to build.gradle

  9. 9

    Override Task in build.gradle

  10. 10

    Convert ant signJar task to gradle

  11. 11

    Is there a way to integrate Gradle / Cucumber / Selenium tests into Browserstack (Java)?

  12. 12

    Gradle build: Execution failed for task ':app:lint'

  13. 13

    Gradle build: Execution failed for task ':app:lint'

  14. 14

    Android - what is gradle task connectedCheck used for

  15. 15

    Gradle leftshift << operator with Task needed? (Is it superfluous)

  16. 16

    Gradle: custom task with jvm arguments for Spring Boot

  17. 17

    Could not get unknown property for task in Gradle?

  18. 18

    Run gradle build(test) in subprojects in a custom task

  19. 19

    Cannot exclude directories for a Gradle copy task

  20. 20

    Gradle: execute tasks sequentially in some task

  21. 21

    Use withType() for configuring Gradle task not compiling in IntelliJ

  22. 22

    gradle: Skipping task ':compileJava' as it has no source files

  23. 23

    Passing Task as parameter to be invoked within loop in async method C#

  24. 24

    cucumber.api.Scenarioのgradle依存関係は何ですか

  25. 25

    Passing parameters to corb uri stage using ml-gradle

  26. 26

    Gradle 5とCucumber-JVMを使用して別のディレクトリからCucumberを実行する

  27. 27

    How to execute a task before executing or building the subprojects in gradle?

  28. 28

    make gradle dependency task to exclude test dependencies in its result

  29. 29

    Android gradle - top level vs module level "build" task

ホットタグ

アーカイブ