【问题标题】:No such property: org.codehaus.grails.INCLUDED_JS_LIBRARIES没有这样的属性:org.codehaus.grails.INCLUDED_JS_LIBRARIES
【发布时间】:2013-09-28 08:29:46
【问题描述】:

要求

我正在尝试在基于功能测试阶段的自定义测试阶段运行我的 JavaScript 测试。基本上它需要:

  • 启动嵌入式 Tomcat
  • 打开一个控制器
  • 检查执行测试的结果

我做了什么

首先,我根据post 创建了我的自定义测试阶段。所以我的 _Events.groovy 看起来像

includeTargets << new File("${basedir}/scripts/_RunJavaScriptUiTests.groovy")

eventConfigureTomcat = { tomcat ->
  tomcat.connector.setAttribute("compression", "on")
  tomcat.connector.setAttribute("compressableMimeType", "text/html,text/xml,text/plain,application/javascript")
  tomcat.connector.port = serverPort
}

eventAllTestsStart = {
  phasesToRun << "uijs"
}

uijsTests = ["uijs"]

uijsTestPhasePreparation = { 
  functionalTestPhasePreparation()
}

uijsTestPhaseCleanUp = { 
  functionalTestPhaseCleanUp()
}
eventTestPhaseEnd = { phase ->
  if( phase == "uijs" ) {
    runJavaScriptUiTests()
  }
}

接下来,我决定使用PhantomJS 打开我的页面并分析执行的测试。所以我在 RunJavaScriptUiTests.groovy 脚本中使用了这个

target(runJavaScriptUiTests:"Running Siesta tests") {

    event("StatusUpdate", ["Siesta test phase..."])

    //this is the script that evaluates the result of the tests
    File script = new File("web-app/js/siesta/siesta-phantomjs-runner.js")

    String home = System.getenv("PHANTOMJS_HOME")
    if(!home) {
        throw new RuntimeException("PHANTOMJS_HOME must be set.")
    }

    String executable = "${home}bin${File.separator}phantomjs"
    String port = System.getProperty("server.port","8080")
    String url = "http://localhost:$port/insoft-ext-ui/siesta" //url of my tests

    println "Running Phantomjs ${executable} ${script.absolutePath} "

    try {
        ant.exec(executable: executable, outputproperty: "cmdOut", failonerror: 'true', errorproperty: "cmdErr") {
            arg(value: script.absolutePath)
            arg(value: url)
        }
        }catch(e) {
        println "ERROR: $e"
        throw e
    }

    try {

        String output = "${ant.project.properties.cmdOut}"
        println output

        }catch(e) {
        event("StatusError",["Exception $e"])
    }

}

我可以看到 functionalTestPhasePreparation 运行,因为它正确启动了我的应用程序。我还可以看到 phantomjs 命令在打印时是正确的:

Running: /desenv/phantomjs-1.9.2/bin/phantomjs /desenv/java/projetos/insoft-ext-ui/web-app/js/siesta/siesta-phantomjs-runner.js http://localhost:8080/insoft-ext-ui/siesta

但这给了我 groovy.lang.MissingPropertyException

groovy.lang.MissingPropertyException: No such property: org.codehaus.grails.INCLUDED_JS_LIBRARIES for class: org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestWrapper
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:273)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.grails.web.filters.JavascriptLibraryFilters$_closure1_closure2_closure3.doCall(JavascriptLibraryFilters.groovy:27)
    at org.codehaus.groovy.grails.web.filters.JavascriptLibraryFilters$_closure1_closure2_closure3.doCall(JavascriptLibraryFilters.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)

有关完整的 Stacktrace,请参阅 here

有趣的是,如果我只是这样做

grails test run-app
phantomjs /desenv/java/projetos/insoft-ext-ui/web-app/js/siesta/siesta-phantomjs-runner.js http://localhost:8080/insoft-ext-ui/siesta

脚本有效,我没有遇到任何异常。

问题

为什么会抛出 MissingPropertyException?我查看了 JavascriptLibraryFilters 并没有找到原因。

编辑

关于Tomcat

我正在使用 Grails 附带的嵌入式 Tomcat,但在 _Events.groovy 中启用了压缩:

eventConfigureTomcat = { tomcat ->
    tomcat.connector.setAttribute("compression", "on")
    tomcat.connector.setAttribute("compressableMimeType", "text/html,text/xml,text/plain,application/javascript")
    tomcat.connector.port = serverPort
}

【问题讨论】:

  • 您的情况有什么更新吗?
  • 我错过了你的答案(不知道为什么)!我会看看这个,谢谢!

标签: spring tomcat grails phantomjs grails-2.2


【解决方案1】:

我没有直接的解决方案,但我可以帮你研究一下。

你的问题的根源显然是org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestWrapper,它应用在你的Tomcat环境中,这就解释了为什么你的代码可以独立运行。

Stack Overflow 上存在其他涉及同一 Spring 类的问题。其中大多数是关于不正确的多部分请求处理的问题。 这会让我相信 PhantomJS 在没有为您的环境提供适当的转换或接口的情况下进行多部分调用。我怀疑可能需要更改您的 Tomcat 或 Grails 配置。

以下是我提到的几个 SO 问题:

这是 Grails / CXF 上一个可能相关的错误:

  • Spring Security bug,指的是 CXF bug,上面写着 “要在 CXF 上启用 MTOM,您必须通过在 Config.groovy 中设置选项 grails.web.disable.multipart=true 来禁用 Grails 的多部分处理”

请提供有关您的 Tomcat / Grails 设置的任何详细信息和/或确认您已经调查了这些潜在的问题路径,以便我们可以打折。

希望此答案能够为您或其他人指明正确的解决方案。

【讨论】:

  • 感谢您的输入,不幸的是我没有处理文件上传,所以在这种情况下我不需要多部分请求。它只是一个呈现视图的普通控制器,但您有一个很好的论据:在这种情况下,PhantomJS 可能会进行一些不同的调用。
  • @SérgioMichels - 您可能没有直接使用上传,但 PhantomJS 可能正在尝试某种多部分并设置了错误的配置参数。
  • 是的,你说得有道理 :-) 我使用的是 Grails 2.2.4 的嵌入式 Tomcat,并且没有配置 grails.web.disable.multipart。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多