0

我正在运行示例 Google 规范,即:

class GoogleHomePageSpec extends GebReportingSpec {

def "first result for wikipedia search should be wikipedia"() {
    given:
    to GoogleHomePage

    expect:
    at GoogleHomePage

    when:
    search.field.value("wikipedia")

    then:
    waitFor { at GoogleResultsPage }

    and:
    firstResultLink.text().startsWith "Wikipedia"

    when:
    firstResultLink.click()

    then:
    waitFor { at WikipediaPage }
}
}

具有以下内容GebSpec

reportsDir = "target/geb-reports"

/* webdriver.*.driver system properties are set in the POM */
driver = { 
    new HtmlUnitDriver();
}

以及以下相关pom.xml摘录:

    <dependency>
        <groupId>org.spockframework</groupId>
        <artifactId>spock-core</artifactId>
        <version>0.7-groovy-2.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.39.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.gebish</groupId>
        <artifactId>geb-spock</artifactId>
        <version>0.9.2</version>
        <scope>test</scope>
    </dependency>

如果我从CLIor运行它,它会失败并显示消息IDE

 First result for wikipedia search should be wikipedia(scratch.GoogleHomePageSpec)  Time elapsed: 0.96 sec  <<< ERROR!
 geb.driver.DriverCreationException: failed to create driver from callback    'GebConfig$_run_closure1@20fcbdaf'
    at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:35)
    at       geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:80)
    at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy)
    at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
    at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
    at geb.Configuration.createDriver(Configuration.groovy:354)
    at geb.Configuration.getDriver(Configuration.groovy:343)
    at geb.Browser.getDriver(Browser.groovy:105)
    at geb.Browser.clearCookies(Browser.groovy:483)
    at geb.Browser.clearCookiesQuietly(Browser.groovy:491)
    at geb.spock.GebSpec.resetBrowser(GebSpec.groovy:45)
    at geb.spock.GebSpec.cleanup(GebSpec.groovy:67)
 Caused by: java.lang.NoClassDefFoundError:   org/apache/commons/collections/set/ListOrderedSet
    at com.gargoylesoftware.htmlunit.CookieManager.<init>(CookieManager.java:59)
    at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:131)
    at   org.openqa.selenium.htmlunit.HtmlUnitDriver.newWebClient(HtmlUnitDriver.java:289)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.createWebClient(HtmlUnitDriver.java:263)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:144)
    at GebConfig.run_closure1(GebConfig.groovy:10)
    at GebConfig.run_closure1(GebConfig.groovy)
    at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:29)
    at   geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:80)
    at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy)
    at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
    at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
    at geb.Configuration.createDriver(Configuration.groovy:354)
    at geb.Configuration.getDriver(Configuration.groovy:343)
    at geb.Browser.getDriver(Browser.groovy:105)
    at geb.Browser.clearCookies(Browser.groovy:483)
    at geb.Browser.clearCookiesQuietly(Browser.groovy:491)
    at geb.spock.GebSpec.resetBrowser(GebSpec.groovy:45)
    at geb.spock.GebSpec.cleanup(GebSpec.groovy:67)

我已经检查过,commons-collection jar 存在并且包含“缺失”类。我根本没有使用ChromeDriver,FirefoxDriverInternetExplorerDriver.

不幸的是,由于环境原因,我必须使用HtmlUnitDriver,所以我真的对这个摸不着头脑。

将不胜感激任何建议。

编辑 1:已设法在我的 Mac 上成功运行此测试的一部分,其余部分超时。但我没有看到与上述相同的错误(在 Windows 上观察到)。

4

1 回答 1

0

通过重建 maven_repo 解决了这个问题,即将旧的移开,因此 maven 被迫在下一次运行测试时重建它。异常不再出现。

于 2014-01-20T16:18:37.820 回答