3

I'm attempting to just try a basic geb script, unfortunately I seem to be having some serious issues getting this off the ground.

I'm using IntelliJ, I've downloaded the geb-core jar from http://mvnrepository.com/artifact/org.gebish/geb-core/0.9.1, as well as its 4 dependencies. I've added them to my IntelliJ project under the project structure as dependencies, when I go to run my basic script

import geb.Browser

Browser.drive {
    go "http://google.com/ncr"
}

I get a very nasty looking error

Caught: java.lang.LinkageError: loader constraint violation in interface itable initialization: when resolving method "com.gargoylesoftware.htmlunit.html.DomNode.getAttributes()Lorg/w3c/dom/NamedNodeMap;" the class loader (instance of org/codehaus/groovy/tools/RootLoader) of the current class, com/gargoylesoftware/htmlunit/html/DomNode, and the class loader (instance of <bootloader>) for interface org/w3c/dom/Node have different Class objects for the type org/w3c/dom/NamedNodeMap used in the signature
java.lang.LinkageError: loader constraint violation in interface itable initialization: when resolving method "com.gargoylesoftware.htmlunit.html.DomNode.getAttributes()Lorg/w3c/dom/NamedNodeMap;" the class loader (instance of org/codehaus/groovy/tools/RootLoader) of the current class, com/gargoylesoftware/htmlunit/html/DomNode, and the class loader (instance of <bootloader>) for interface org/w3c/dom/Node have different Class objects for the type org/w3c/dom/NamedNodeMap used in the signature
    at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:190)
    at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:268)
    at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:156)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:455)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:329)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:394)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:474)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:452)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:181)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:191)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:187)
    at geb.driver.NameBasedDriverFactory.getDriver(NameBasedDriverFactory.groovy:42)
    at geb.driver.CachingDriverFactory$_getDriver_closure3.doCall(CachingDriverFactory.groovy:80)
    at geb.driver.CachingDriverFactory$_getDriver_closure3.doCall(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.go(Browser.groovy:394)
    at geb.Browser$go$1.callCurrent(Unknown Source)
    at geb.Browser.go(Browser.groovy:386)
    at gebtest$_run_closure1.doCall(gebtest.groovy:14)
    at gebtest$_run_closure1.doCall(gebtest.groovy)
    at geb.Browser.drive(Browser.groovy:860)
    at geb.Browser$drive$0.callStatic(Unknown Source)
    at geb.Browser.drive(Browser.groovy:830)
    at geb.Browser$drive.call(Unknown Source)
    at gebtest.run(gebtest.groovy:13)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
dkirlin
  • 315
  • 4
  • 19
  • This looks like a duplicate of http://stackoverflow.com/questions/23545290/linkage-error-using-webdriver-in-a-netbeans-platform-project. I got the same thing. Had one in the jdk and one in xml-apis-1.4.01.jar loaded from htmlunit. – Interlated Jun 05 '14 at 12:50
  • Yeah, similar problem – dkirlin Jun 05 '14 at 13:22
  • I added xml-apis-1.4.01.jar to the endorsed directory. Then I get SAXParserFactoryImpl not found. Going to go onto something else. – Interlated Jun 06 '14 at 04:51

2 Answers2

5

I would suggest using Gradle that will save you from manually setting up a project and resolving Geb dependencies. The simplest way to do it using gradle is:

Install GVM Tool: http://gvmtool.net/

Install Gradle via gvm: gvm install gradle 1.12

Create a build.gradle file:

apply plugin: 'idea'
apply plugin: 'groovy'

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.gebish:geb-core:0.9.3'
    compile 'org.codehaus.groovy:groovy-all:2.3.3'
    compile 'org.seleniumhq.selenium:selenium-firefox-driver:2.42.2'
}

Create a src/main/groovy directory.

Run gradle idea.

Open the generated idea project file.

Drop your Geb script inside of the src/main/groovy directory and run it.

erdi
  • 6,944
  • 18
  • 28
0

I'm going to leave an answer for any future guy who will stumble upon a similar error (with or without htmlunit involved).

I have just faced the same java.lang.LinkageError exception using htmlunit with geb. My solution is to exclude the transitive dependency of the xml-apis package brought in by htmlunit.

If you are using a groovy script like me, the instructions to use htmlunit without the transitive dep is the following:

@Grab('net.sourceforge.htmlunit:htmlunit:2.8')
@GrabExclude('xml-apis:xml-apis')

Other build tools such as maven or gradle have a similar syntax.

Giuseppe Ricupero
  • 6,134
  • 3
  • 23
  • 32