gpt4 book ai didi

grails - Grails、Geb 和 PhantomJS 的功能测试不起作用

转载 作者:行者123 更新时间:2023-12-01 03:48:05 24 4
gpt4 key购买 nike

我正在使用 Gebish & HtmlUnitDriver 运行 Spock 测试。到现在为止还挺好。

出于速度原因,我将驱动程序更改为 PhantomJS:http://phantomjs.org/

我的 GebConfigs.groovy 看起来像这样:

import org.openqa.selenium.phantomjs.PhantomJSDriver
import org.openqa.selenium.remote.DesiredCapabilities
import org.openqa.selenium.WebDriver
import org.openqa.selenium.Dimension

driver {
ArrayList cliArgsCap = new ArrayList();
cliArgsCap.add("--web-security=false");
cliArgsCap.add("--ssl-protocol=any");
cliArgsCap.add("--ignore-ssl-errors=true");

DesiredCapabilities desiredCapabilities = new DesiredCapabilities()
desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);

PhantomJSDriver d = new PhantomJSDriver(desiredCapabilities)
d
}

如您所见,无论 PhantomJSDriver 应该用于测试什么。

我的 BuildConfig.groovy
test "org.gebish:geb-spock:$gebVersion"
test "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
test "org.seleniumhq.selenium:selenium-remote-driver:$seleniumVersion"
test "org.seleniumhq.selenium:selenium-htmlunit-driver:$seleniumVersion"
test "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
test "org.spockframework:spock-grails-support:0.7-groovy-2.0"


test "org.grails:grails-datastore-test-support:1.0-grails-2.4"

test( "com.github.detro.ghostdriver:phantomjsdriver:1.1.0" ) {
transitive = false
}

phantomjs.exe 位于:
C:\Apps\selenium\phantomjs\phantomjs.exe
C:\Apps\selenium\phantomjs 在我的 PATH 中。我可以在交互模式下通过 cmd: phantomjs 运行它。

问题

由于某些不清楚的原因,geb 仍在使用 HtmlUnitDriver。见日志:
Error |
2014-08-15 14:01:26,630 [JS executor for com.gargoylesoftware.htmlunit.WebClient@527a4013] ERROR
javascript.StrictErrorReporter - runtimeError: message=[The data necessary to complete this
operation is not yet available.] sourceName=[http://localhost:8080/myapp/aui/js/aui-all.js] line=
[1] lineSource=[null] lineOffset=[0]

在这种情况下为什么不使用 phantomjsdriver 的任何想法?

最佳答案

我已经使用 Grails 2.0.4 应用程序启动并运行了 phantomjs。我的 buildConfig.groovy 看起来像这样:

def gebVersion = "0.9.2"
def seleniumVersion = "2.35.0"

...

test "org.gebish:geb-spock:$gebVersion"
test "org.gebish:geb-junit4:$gebVersion"
test( "com.github.detro.ghostdriver:phantomjsdriver:1.0.1" ) {
transitive = false
exclude "xml-apis"
exclude "xercesImpl"
}
test ("org.seleniumhq.selenium:selenium-remote-driver:$seleniumVersion") { // Needed by phantomjsdriver
exclude "xerces"
exclude "xercesImpl"
}

希望有帮助

更新: 不得不在我自己的例子上做一点工作,但结果是一个带有 phantomjs 的可工作的 Grails 2.4.2 应用程序: https://github.com/rdmueller/SO25324259(抱歉格式太糟糕了 - 只在我 checkin 后才看到)。

顺便说一句:我没有让你的 DesiredCapabilities 工作:-(

PS:你知道举报功能吗? https://github.com/rdmueller/SO25324259/blob/master/test/functional/DemoSpec.groovy#L14

它使用 headless phantomjs 浏览器截取屏幕截图 - 非常酷的功能!

关于grails - Grails、Geb 和 PhantomJS 的功能测试不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25324259/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com