對不起,所有這些代碼,但我沒有線索是什麼使我的問題,所以它在這裏。Geb Firefox驅動程序:爲什麼我的測試運行兩次?
我配置了geb插件以使用JUnit運行功能測試。所以,我在我的buildConfig.groovy:
def seleniumVersion = "2.29.0"
def gebVersion = "0.7.0"
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
// runtime 'mysql:mysql-connector-java:5.1.5'
provided('com.oracle:oracle:11.1.0.7.0')
provided('com.oracle:i18n:10.2.0.5')
test ("org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion") {
export = false
}
test("org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"){
excludes "commons-io"
export = false
}
test ("org.seleniumhq.selenium:selenium-ie-driver:$seleniumVersion") {
export = false
}
test ("org.seleniumhq.selenium:selenium-support:$seleniumVersion") {
export = false
}
test ("org.seleniumhq.selenium:selenium-remote-driver:$seleniumVersion") {
export = false
}
test ("org.codehaus.geb:geb-junit4:$gebVersion") {
export = false
}
}
plugins {
build(":tomcat:$grailsVersion") {
export = false
excludes 'svn'
}
compile (":hibernate:$grailsVersion") {
export = false
excludes 'svn'
}
build (":release:2.0.0") {
excludes 'commons-io','http-builder'
export = false
}
compile(":spring-security-core:1.2.7.3") { excludes 'svn' }
compile(":spring-security-ldap:1.0.6")
compile (":remote-control:1.3") {
export = false
}
test(":geb:$gebVersion") {
export = false
}
}
而且我有一個GebConfig.groovy在我的conf文件夾:
driver = {
//def driver = new HtmlUnitDriver()
//driver.javascriptEnabled = true
//driver
def driver = new FirefoxDriver()
driver
}
environments {
// run as 「grails -Dgeb.env=chrome test-app」
// See: http://code.google.com/p/selenium/wiki/ChromeDriver
chrome {
driver = { new ChromeDriver() }
}
// run as 「grails -Dgeb.env=firefox test-app」
// See: http://code.google.com/p/selenium/wiki/FirefoxDriver
firefox {
driver = { new FirefoxDriver() }
}
}
我的登錄功能測試:
class LoginTests extends GebReportingTest {
@Test
void login() {
to LoginPage
at LoginPage
username = "SERGIO"
password = "SERGIO"
loginButton.click()
assert at(IndexPage)
link.click()
}
}
這是我的兩頁:
class LoginPage extends Page {
static url = "login/auth"
static at = {
title ==~ /Efetuar Login/
}
static content = {
loginForm { $("form", id: "loginForm") }
username { $("input", type:"text", id:"username") }
password { $("input", type:"password", id:"password") }
loginButton{ $("input", type:"submit", id:"submit") }
}
}
class IndexPage extends Page {
static at = {
title ==~ /Security Service Index View/
}
static content = {
description { $('h1') }
link { $('a') }
}
}
出於某種原因,我的功能測試運行兩次,並沒有不管我如何開始的:
grails test-app :functional
grails test-app -functional
這可能不是你的問題的原因,但你爲什麼需要對selenium-remote-driver的依賴?另外,你能說明你的測試運行兩次是什麼意思嗎?兩次FF?你正在使用哪個Grails版本?你還安裝了哪些其他插件? – erdi
我編輯了安裝的插件列表。我只是複製了一個例子中的硒依賴關係,所以遠程來自於這個:) –
通過運行兩次,我的意思是功能測試運行兩次(在控制檯「運行測試1」中出現兩次,FF也做了兩次他的工作 –