我有:
• java version "1.6.0_37"
• Java(TM) SE Runtime Environment (build 1.6.0_37-b06-434-10M3909)
• Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01-434, mixed mode)
• Grails 2.2.0
• Groovy 2.0
• GEB core 0.7.2
以及所有必需的罐子。 我正在尝试运行一个简单的GEB计划:
我在模块依赖项中拥有所有groovy jar,并且我将buildconfig和gebconfig与新程序及其错误相关联。我知道这个新错误是调用驱动程序的问题,但我需要帮助来找出整个问题并解决它。感谢
BUILDCONFIG.GROOVY
grails.servlet.version = "2.5" //Change depending on target container compliance(2.5 or 3.0)
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
grails.project.war.file = "target/${appName}.war"
grails.project.dependency.resolution = {
inherits("global") {}
log "warn"
checksums true // Whether to verify checksums on resolve
def gebVersion = "0.7.2"
def seleniumVersion = "2.25.0"
repositories {
inherits true
}
dependencies {
test("org.seleniumhq.selenium:selenium-htmlunit-driver:$seleniumVersion") {
exclude "xml-apis"
}
test("org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion")
test("org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion")
// test 'org.seleniumhq.selenium:selenium-firefox-driver:latest.release'
// test 'org.seleniumhq.selenium:selenium-chrome-driver:latest.release'
//
// test('org.seleniumhq.selenium:selenium-htmlunit-driver:latest.release') {
// exclude 'xml-apis'
// }
test "org.codehaus.geb:geb-junit4:$gebVersion"
}
plugins {
test ":geb:0.9.0-RC-1"
}
}
// Use a local copy of a platform plugin instead of the installed plugin
grails.plugin.location.platform = "../../plugins/platform"
GEBCONFIG.GROOVY
/*
This is the Geb configuration file.
See: http://www.gebish.org/manual/current/configuration.html
*/
import groovy.transform.Field
//import org.openqa.selenium.htmlunit.HtmlUnitDriver
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.chrome.ChromeDriver
// Use htmlunit as the default
// See: http://code.google.com/p/selenium/wiki/HtmlUnitDriver
//driver = {
//def driver = new HtmlUnitDriver()
// driver.javascriptEnabled = true
// driver
//}
driver= {
new FirefoxDriver()
}
waiting {
timeout = 5
}
environments {
// run as “grails -Dgeb.env=chrome SampleTests-app”
// See: http://code.google.com/p/selenium/wiki/ChromeDriver
chrome {
driver = { new ChromeDriver() }
}
// run as “grails -Dgeb.env=firefox SampleTests-app”
// See: http://code.google.com/p/selenium/wiki/FirefoxDriver
firefox {
driver = { new FirefoxDriver() }
}
}
TEST
package com.test.platform.test
import geb.junit4.GebReportingTest
import geb.Browser
import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
class AuthTests extends GebReportingTest {
void testLoginLogout() {
Browser.drive {
//goto login page & assert location
go("http://localhost:8080/test")
assert (getTitle() == "Welcome to test")
}
}
}
错误
Failure: testLoginLogout(com.test.platform.test.AuthTests)
| geb.driver.DriverCreationException: failed to create driver from callback 'GebConfig$_run_closure3_closure5_closure7@c471242'
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:35)
at geb.driver.CachingDriverFactory$_getDriver_closure3.doCall(CachingDriverFactory.groovy:80)
at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
at geb.Configuration.createDriver(Configuration.groovy:306)
at geb.Configuration.getDriver(Configuration.groovy:295)
at geb.Browser.getDriver(Browser.groovy:101)
at geb.Browser.clearCookies(Browser.groovy:407)
at geb.Browser.clearCookiesQuietly(Browser.groovy:415)
at geb.junit4.GebTest.resetBrowser(GebTest.groovy:46)
Caused by: java.lang.NoSuchMethodError: org.openqa.selenium.logging.LocalLogs.getNullLogger()Lorg/openqa/selenium/logging/LocalLogs;
at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.<init>(FirefoxDriver.java:325)
at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.<init>(FirefoxDriver.java:321)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:188)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:183)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:179)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:92)
at GebConfig$_run_closure3_closure5_closure7.doCall(GebConfig.groovy:39)
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:29)
... 9 more
答案 0 :(得分:1)
为什么使用geb插件0.9.0-RC-1和geb-junit4 0.7.2?您应该为它们使用相同的版本。
此外,您不需要在测试中使用Browser.drive块,因为测试中有一个隐式浏览器,它也由基类管理。看一下Spock example in Geb docs,它与JUnit基类具有完全相同的变量。
因此,您的测试可能看起来像:
package com.test.platform.test
import geb.junit4.GebReportingTest
import geb.Browser
class AuthTests extends GebReportingTest {
void testLoginLogout() {
go("http://localhost:8080/test")
assert(getTitle() == "Welcome to test")
}
}
答案 1 :(得分:0)
可以尝试使用FF驱动程序
{
FirefoxBinary firefoxBinary = new FirefoxBinary()
firefoxBinary.setEnvironmentProperty("DISPLAY",":77")
firefoxBinary.setTimeout(20000l)
FirefoxProfile profile = new FirefoxProfile()
driver = {
new FirefoxDriver(firefoxBinary, profile)
}
}
在我的项目上它是有效的。 关于其他的裤子,我无能为力。