使用Grails、Geb和;幻影不起作用

使用Grails、Geb和;幻影不起作用,grails,selenium,groovy,phantomjs,spock,Grails,Selenium,Groovy,Phantomjs,Spock,我正在用Gebish和HtmlUnitDriver运行Spock测试。到目前为止还不错 出于速度原因,我将驱动程序更改为PhantomJS: 我的GebConfigs.groovy如下所示: import org.openqa.selenium.phantomjs.PhantomJSDriver import org.openqa.selenium.remote.DesiredCapabilities import org.openqa.selenium.WebDriver import org

我正在用Gebish和HtmlUnitDriver运行Spock测试。到目前为止还不错

出于速度原因,我将驱动程序更改为PhantomJS:

我的
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
}
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"
    }
正如您所看到的,无论测试应该使用什么样的PhantomJSDriver

my
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
在我的
路径中。我可以在交互模式下通过
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吗?

我已经安装了phantomjs,并使用Grails 2.0.4应用程序运行。我的buildConfig.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
}
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"
    }
希望有帮助

更新:在我自己的示例中需要做一些工作,但结果是一个运行良好的Grails 2.4.2应用程序,带有phantomjs:(很抱歉格式太糟糕了-只有在我签入后才看到)

顺便说一句:我没有得到你想要的工作能力:-(

附言:你知道报告的特点吗


这是你的无头phantomjs浏览器的屏幕截图-非常酷的功能!

你收到任何错误消息吗?@ArtjomB我在这篇文章之前查看了这篇文章。它在http/https上都不起作用。只是想这可能是原因,但事实并非如此。phantomjs甚至没有被使用(见更新的问题)@Ralf我发布了一些日志,以表明phantomjs由于某些不清楚的原因甚至没有被使用&我更新了这个问题。谢谢。到目前为止还没有工作:/你能添加你的GebCOnfigs.groovy设置吗?你需要哪个Grails版本的配置?如果今晚我能创建一个演示项目,我会的……我正在使用Grails 2.4.2:)那太不可思议了!请参阅我的更新以获取解决方案。。。如果这仍然不适用于您,请进行清理并删除临时%userhome%/.grails文件夹。。。