0

我有:

•   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() }

    }

}

测试

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
4

2 回答 2

1

为什么要使用 geb 插件 0.9.0-RC-1 和 geb-junit4 0.7.2?您应该为它们使用相同的版本。

此外,您不需要在测试中使用 Browser.drive 块,因为您的测试中有一个隐式浏览器可用,它也由基类管理。查看Geb docs 中的 Spock 示例,它具有与 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")
    }

}
于 2013-02-03T12:41:08.640 回答
0

可以试试这个 FF 驱动程序

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

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

在我的项目中它的工作。关于其他brousers,我无能为力。

于 2013-02-08T15:30:39.703 回答