播放1.2.2 - 标签内的标签不再允许吗?

时间:2011-08-09 22:10:56

标签: java templates playframework

我正在开发一个应用程序,在我的selenium测试中,我使用了几个标签来执行重复性任务。两个标签是:

应用/视图/标签/ loginAs.html

*{ Tag for running selenium tests when being logged in }*

#{if !_keepData}
#{braindumpFixture delete:'all', load:'users.yml' /}
#{/if}

#{selenium}
 ... some selenium code to log into the application
#{/selenium}

应用/视图/标签/ braindumpFixture.html

%{
if(_delete == 'all') {
play.test.Fixtures.deleteAll()
} else if(_delete) {
play.test.Fixtures.delete(_delete)
}
}%

%{
if(_load) {
play.test.Fixtures.load(_load)
}
// finally make sure the index is correctly updated.
new application.jobs.CompleteReindexJob().doJob();
}%

这些在Play 1.1中没有问题。切换到播放1.2.2后,运行使用loginAs的selenium测试时出现以下异常:

测试/硒/ AddCard.test.html

*{ Tests adding a simple card }*

#{loginAs login:'foobar@foobar.com', password:'foobar' /}

#{selenium}
open('@{Application.index()}')
... more selenium stuff here
#{/selenium}

例外是:

play.exceptions.TemplateExecutionException: Cannot get property 'data' on null object
    at play.templates.BaseTemplate.throwException(BaseTemplate.java:84)
    at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:252)
    at play.templates.GroovyTemplate$ExecutableTemplate.invokeTag(GroovyTemplate.java:374)
    at /test/selenium/AddCard.test.html.(line:3)
    at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:229)
    at play.templates.Template.render(Template.java:26)
    at play.templates.GroovyTemplate.render(GroovyTemplate.java:184)
    at controllers.TestRunner.run(TestRunner.java:107)
    at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:543)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:499)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:475)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:470)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:158)
    at Invocation.HTTP Request(Play!)
Caused by: java.lang.NullPointerException: Cannot get property 'data' on null object
    at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:229)
    ... 12 more

当我在调用braindumpFixture时删除#{if!_keepData}时,我得到一个EmptyStackException:

play.exceptions.TemplateExecutionException
    at play.templates.BaseTemplate.throwException(BaseTemplate.java:84)
    at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:252)
    at play.templates.Template.render(Template.java:26)
    at play.templates.GroovyTemplate.render(GroovyTemplate.java:184)
    at controllers.TestRunner.run(TestRunner.java:107)
    at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:543)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:499)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:475)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:470)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:158)
    at Invocation.HTTP Request(Play!)
Caused by: java.util.EmptyStackException
    at java.util.Stack.peek(Stack.java:85)
    at java.util.Stack.pop(Stack.java:67)
    at play.templates.TagContext.exitTag(TagContext.java:31)
    at play.templates.GroovyTemplate$ExecutableTemplate.invokeTag(GroovyTemplate.java:380)
    at /test/selenium/AddCard.test.html.(line:3)
    at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:229)
    ... 9 more

我想知道Play 1.2中的标签是否发生了根本性的变化,我只是在文档中忽略了它,或者这可能是一个错误。任何关于解决这个谜语的想法都是受欢迎的。

2 个答案:

答案 0 :(得分:3)

问题是#{fixture}标签。它会在加载yml文件时终止内部堆栈。请参阅https://play.lighthouseapp.com/projects/57987-play-framework/tickets/1026-using-tags-inside-tags-is-broken-since-play-121#ticket-1026-3

作为一种解决方法,您可以创建灯具标签的修改版本:

%{
    if(_delete == 'all') {
        play.test.Fixtures.deleteAll()
    } else if(_delete) {
        play.test.Fixtures.delete(_delete)
    }
}%

%{
    if(_load) {
        // Workaround (save the stack)
        stack = play.templates.TagContext.currentStack.get();

        play.test.Fixtures.load(_load)

        // Workaround (restore the stack)
        play.templates.TagContext.currentStack.set(stack);
    }
}%

%{
    if(_arg && _arg instanceof String) {
        try {
            play.Play.classloader.loadClass(_arg).newInstance()
        } catch(Exception e) {
            throw new play.exceptions.TagInternalException('Cannot apply ' + _arg + ' fixture because of ' + e.getClass().getName() + ', ' + e.getMessage())
        }
    }
%}

答案 1 :(得分:1)

我不知道应该有什么改变来阻止它工作,所以会发现这是一个错误。