2011-08-09 45 views
1

我正在開發一個應用程序,並在我的硒測試中使用多個標記來完成重複任務。兩個標籤:播放1.2.2 - 標籤內部的標籤不再被允許嗎?

應用程序/視圖/標籤/ 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(); 
}% 

沒有問題。這些工作玩1.1。

測試/硒/ AddCard.test.html

*{ Tests adding a simple card }* 

#{loginAs login:'[email protected]', password:'foobar' /} 

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

唯一的例外是:

切換播放1.2.2後,我運行使用loginAs硒測試時,出現以下情況例外
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 

當我刪除了#{如果_keepData!}調用braindumpFixture圍繞我得到的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中的標籤是否發生了根本性的變化,我只是在文檔中忽略了它,或者這可能是一個錯誤。任何解決這個謎題的想法都是受歡迎的。

+1

我們能看到這一點:在/test/selenium/AddCard.test.html.(line:3)? –

+0

我加了。它只是調用該行中的標籤。 –

回答

1

我不知道任何事情都應該改變,以阻止工作,所以期待這是一個錯誤。

+0

幾個庫已經升級,但沒有什麼應該破壞向後兼容性。 –

3

問題是#{夾具}標籤。加載一個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()) 
     } 
    } 
%}