无法在Maven下使用HtmlUnitDriver运行Geb测试

时间:2014-01-17 17:59:47

标签: selenium-webdriver spock geb htmlunit-driver

我正在运行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>

如果我从CLIIDE运行该消息,则该消息失败:

 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存在且包含'missing'类。 我使用ChromeDriverFirefoxDriverInternetExplorerDriver完全没有收到此错误。

不幸的是出于环境原因,我不得不使用HtmlUnitDriver所以我真的对这个问题感到头疼。

会对任何建议表示感谢。

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

1 个答案:

答案 0 :(得分:0)

通过重建maven_repo解决了这个问题,即移开旧的maven_repo,以便maven在下次测试运行时被迫重建它。 例外不再出现。