Unable to run cucumber features in debug mode in intellij using gradle
Asked Answered
Q

2

12

When I run my configuration in debug, all the tests are executed without stopping to the breakpoints. Anyone knows how to run/debug the features using gradle?

I also tried an application configuration but the system properties "geb.browser and geb.environment" are not being set, which causes null pointer exception.

Configuration:

enter image description here

build.gradle:

import org.apache.tools.ant.taskdefs.condition.Os
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "com.github.samueltbrown:gradle-cucumber-plugin:0.9"
        classpath "info.cukes:cucumber-core:1.2.4"
    }
}

ext {
    ext {
        groovyVersion = '2.4.4'
        gebVersion = '0.12.2'
        seleniumVersion = '2.48.2'
        chromeDriverVersion = '2.20'
        cucumberJvmVersion = '1.2.2'
     }
}

apply plugin: 'groovy'
apply plugin: 'java'
apply from: "gradle/osSpecificDownloads.gradle"
apply plugin: "com.github.samueltbrown.cucumber"
apply from: "gradle/idea/idea.gradle"

repositories {
    mavenCentral()
}
dependencies {
    testCompile "org.gebish:geb-core:$gebVersion"
    testCompile "org.codehaus.groovy:groovy-all:$groovyVersion"

    // HttpBuilder
    testCompile "org.codehaus.groovy.modules.http-builder:http-builder:0.7.1"

    // Selenium support
    testCompile "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
    testCompile "org.seleniumhq.selenium:selenium-api:$seleniumVersion"

    testCompile "info.cukes:cucumber-core:$cucumberJvmVersion"
    testCompile "info.cukes:cucumber-groovy:$cucumberJvmVersion"

    testCompile "io.jdev.geb:geb-cucumber:0.3"

    cucumberRuntime "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
    cucumberRuntime "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"

}

cucumber {
    formats = [
            'pretty', // prints nice format out to the console
            'html:build/reports/cucumber', // html
            'junit:build/cucumber.xml' // junit format for integration with CI tool etc
    ]

    glueDirs = ['src/test/groovy/com/stepsDefs']
    featureDirs = ['src/cucumber/resources']
}

tasks.cucumber {
    dependsOn unzipChromeDriver

    final def environment = System.getProperty('geb.environmemt')
    // set environments
    switch (environment) {
        case 'alpha':
            System.setProperty("geb.build.baseUrl", "http://www.google.com")
            System.setProperty("apiKey", "")
            break
        case 'ci':
            System.setProperty("geb.build.baseUrl", "http://www.google.com")
            System.setProperty("apiKey", "")
            break
        case 'silo122':
            System.setProperty("geb.build.baseUrl", "http://www.google.com")
            System.setProperty("apiKey", "")
            break
        default:
            println("Environment argument is not supported - Available options:\n- alpha\n- ci\n- local\n- silo122\n- stage")
            System.exit(0)
            break
    }

    def chromeDriverFilename = Os.isFamily(Os.FAMILY_WINDOWS) ? "chromedriver.exe" : "chromedriver"
    jvmOptions.systemProperties([
            "webdriver.chrome.driver": new File(unzipChromeDriver.outputs.files.singleFile, chromeDriverFilename).absolutePath,
            "geb.cucumber.step.packages": "pages",
            "geb.env": System.getProperty("geb.browser"),
            "geb.build.baseUrl":System.getProperty("geb.build.baseUrl"),
            "envName": System.getProperty("geb.environmemt")
    ])

}

apply from: "gradle/ci.gradle"
Quartermaster answered 7/1, 2016 at 19:47 Comment(1)
I was not able to find where gradle arugment system for Intelljis ?Ankh
W
3

Where are your breakpoints set? If they are in your feature file, then unfortunately you cannot debug those as they are parsed during runtime by cucumber. The breakpoints must be inside your definition files or any other source file. If you have duplicate steps in the feature file, you can try hitting pause on your IDE right before the step you want to debug hits and then set the new breakpoint on the code that you want to debug.

Wuhsien answered 10/3, 2019 at 9:13 Comment(0)
W
1

You can refactor the Gradle build to use a JUnit wrapper for Cucumber, as described in this answer for a similar problem for VS Code. This means you won't need any cucumber plugin for Gradle any more. Then re-import the gradle build into IntelliJ, and if necessary, right-click on the test task in IntelliJ and edit the configuration to add any necessary arguments. Then debugging will work.

Weigand answered 21/4, 2021 at 16:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.