首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >与geb的联动误差

与geb的联动误差
EN

Stack Overflow用户
提问于 2014-06-04 14:02:31
回答 2查看 997关注 0票数 3

我试图尝试一个基本的geb脚本,不幸的是,我似乎有一些严重的问题,使这一步开始。

我使用的是IntelliJ,我已经从http://mvnrepository.com/artifact/org.gebish/geb-core/0.9.1下载了geb核心jar,以及它的4个依赖项。在运行基本脚本时,我将它们作为依赖项添加到项目结构下的IntelliJ项目中

代码语言:javascript
复制
import geb.Browser

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

我犯了一个很难看的错误

代码语言:javascript
复制
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)
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-06-12 22:52:35

我建议使用Gradle来避免手动设置项目和解决Geb依赖关系。使用gradle最简单的方法是:

安装GVM工具http://gvmtool.net/

通过gvm:gvm install gradle 1.12安装Gradle

创建一个build.gradle文件:

代码语言:javascript
复制
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'
}

创建一个src/main/groovy目录。

运行gradle idea

打开生成的idea项目文件。

将您的Geb脚本放到src/main/groovy目录中并运行它。

票数 5
EN

Stack Overflow用户

发布于 2021-08-13 11:31:13

我将为任何将来会遇到类似错误的人留下一个答案(不管是否涉及htmlunit )。

我刚刚遇到了同样的java.lang.LinkageError异常,使用htmlunitgeb。我的解决方案是排除htmlunit带来的htmlunit包的传递依赖关系。

如果您使用的是像我这样的groovy脚本,那么在没有传递dep的情况下使用htmlunit的说明如下:

代码语言:javascript
复制
@Grab('net.sourceforge.htmlunit:htmlunit:2.8')
@GrabExclude('xml-apis:xml-apis')

其他构建工具(如mavengradle )具有类似的语法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24039574

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档