12

当我在调试中运行我的配置时,所有测试都在不停止到断点的情况下执行。任何人都知道如何使用 gradle 运行/调试功能?

我还尝试了应用程序配置,但未设置系统属性“geb.browser 和 geb.environment”,这会导致空指针异常。

配置:

在此处输入图像描述

构建.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"
4

2 回答 2

3

你的断点设置在哪里?如果它们在您的功能文件中,那么不幸的是您无法调试它们,因为它们在运行时由 cucumber 解析。断点必须在您的定义文件或任何其他源文件中。如果功能文件中有重复的步骤,可以尝试在要调试的步骤命中之前在 IDE 上点击暂停,然后在要调试的代码上设置新断点。

于 2019-03-10T09:13:35.140 回答
1

您可以重构 Gradle 构建以使用 Cucumber 的 JUnit 包装器,如针对 VS Code 的类似问题的答案中所述。这意味着您将不再需要 Gradle 的任何黄瓜插件。然后将 gradle 构建重新导入 IntelliJ,如有必要,右键单击 IntelliJ 中的测试任务并编辑配置以添加任何必要的参数。然后调试将起作用。

于 2021-04-21T16:27:26.833 回答