2013-02-01 34 views
0

我:GEB測試...驅動程序回調問題

• 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 '[email protected]' 
    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 

回答

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") 
    } 

} 
+0

它仍然顯示相同的錯誤...我將geb插件版本更改爲0.7.2,但同樣的錯誤重複。有任何想法嗎? – Dee

0

可能嘗試一下本作FF驅動

{ 
    FirefoxBinary firefoxBinary = new FirefoxBinary() 
    firefoxBinary.setEnvironmentProperty("DISPLAY",":77") 
    firefoxBinary.setTimeout(20000l) 
    FirefoxProfile profile = new FirefoxProfile() 

    driver = { 
     new FirefoxDriver(firefoxBinary, profile) 
    } 
} 

我的項目它的工作。 關於其他brousers,我不禁。