【发布时间】:2018-10-05 18:23:05
【问题描述】:
我正在使用 Geb/Spock 进行自动化测试。我使用 Gradle 作为我的构建工具。
我想调用不同的 gradle 任务来构建和运行特定规范(测试)或一套规范。
我对 gradle 构建生命周期的了解不够,无法完全理解这里发生了什么:https://github.com/geb/geb-example-gradle/blob/master/build.gradle
plugins {
id "idea"
id "groovy"
id "com.energizedwork.webdriver-binaries" version "1.4"
id "com.energizedwork.idea-base" version "1.4"
}
ext {
// The drivers we want to use
drivers = ["firefox", "chrome", "chromeHeadless"]
ext {
groovyVersion = '2.4.12'
gebVersion = '2.2'
seleniumVersion = '3.6.0'
chromeDriverVersion = '2.32'
geckoDriverVersion = '0.18.0'
}
}
repositories {
mavenCentral()
}
dependencies {
// If using Spock, need to depend on geb-spock
testCompile "org.gebish:geb-spock:$gebVersion"
testCompile("org.spockframework:spock-core:1.1-groovy-2.4") {
exclude group: "org.codehaus.groovy"
}
testCompile "org.codehaus.groovy:groovy-all:$groovyVersion"
// If using JUnit, need to depend on geb-junit (3 or 4)
testCompile "org.gebish:geb-junit4:$gebVersion"
// Drivers
testCompile "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
testCompile "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
}
webdriverBinaries {
chromedriver chromeDriverVersion
geckodriver geckoDriverVersion
}
drivers.each { driver ->
task "${driver}Test"(type: Test) {
group JavaBasePlugin.VERIFICATION_GROUP
outputs.upToDateWhen { false } // Always run tests
systemProperty "geb.build.reportsDir", reporting.file("geb/$name")
systemProperty "geb.env", driver
}
}
test {
dependsOn drivers.collect { tasks["${it}Test"] }
enabled = false
}
tasks.withType(Test) {
maxHeapSize = "1g"
jvmArgs '-XX:MaxMetaspaceSize=128m'
testLogging {
exceptionFormat = 'full'
}
}
tasks.withType(GroovyCompile) {
groovyOptions.forkOptions.memoryMaximumSize = '256m'
}
我尝试将以下内容插入 build.gradle:
task dataGen {
include '**com.company.project.spec.util/DataGenerationUtilSpec.groovy'
}
task sanity {
include '**com.company.project.spec.sanity.*'
}
但调用这些任务 (gradle sanity) 会导致构建失败:
Could not find method include() for arguments [**com.company.project.spec.util/DataGenerationUtilSpec.groovy] on task ':dataGen' of type org.gradle.api.DefaultTask
显然有现有的构建说明,因为我可以调用 gradle build 并且所有规范都在 Chrome 上运行,我只是不确定如何添加更多任务
【问题讨论】:
-
你能更好地解释一下这个问题的标题吗?你的意思是运行不同的情况(理智、回归等)还是在不同的浏览器上运行(chrome、firefox)
-
@Royg 我想我可以传入哪个浏览器 ID 喜欢用作运行时参数,但我需要测试来运行一组特定的案例
-
对于这种用法,您可以使用下面的答案。
-
目前尚不清楚您要实现什么 Doug Clark - 您的问题标题提到在多个浏览器中运行测试,但您的问题文本似乎是关于运行测试子集作为不同测试任务的一部分。还不清楚您的设置是什么,因为根据 ToYonos 的回答,您的一个 cmets 似乎没有任何测试 - 您得到的是
Skipping task ':patientGen' as it has no source files。如果您希望我们能够为您提供帮助,您需要更好地向我们展示全貌。
标签: gradle automated-tests spock geb