Search code examples
selenium-webdriverspockgebhtmlunit-driver

Can't run Geb tests using HtmlUnitDriver under Maven


I am running the example Google spec, i.e:

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

with the following GebSpec:

reportsDir = "target/geb-reports"

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

and the following relevant pom.xml excerpt:

    <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>

and it fails with the message if I run it from CLI or 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)

I've checked and the commons-collection jar is present and contains the 'missing' class. I don't get this error at all using ChromeDriver, FirefoxDriver and InternetExplorerDriver.

Unfortunately for environmental reasons I have to use HtmlUnitDriver so I'm really scratching my head about this one.

Would be grateful for any suggestions.

EDIT 1: Have managed to run a portion of this test successfully on my Mac, the remainder times out. But am not seeing the same errors as above (which were observed on Windows).


Solution

  • Resolved this problem by rebuilding the maven_repo i.e. moving the old one out of the way so maven is forced to rebuild it on the next run of the tests. The exception no longer appears.