如何获取所有JS文件名
如何获取我的应用程序的所有 JS 文件名称?
我测试过:
@Inject
private ClientInfrastructure javascriptStack;
void onActivate(){
mesJavaScripts=javascriptStack.getJavascriptStack();
for(Asset javascript : mesJavaScripts){
System.out.println(javascript.toString());
}
}
但是我没有所有的JS。我使用优质服务吗?
谢谢
How can I get all JS files name of my application ?
I tested :
@Inject
private ClientInfrastructure javascriptStack;
void onActivate(){
mesJavaScripts=javascriptStack.getJavascriptStack();
for(Asset javascript : mesJavaScripts){
System.out.println(javascript.toString());
}
}
But I do not have all the JS. Do I use the good service ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还是不符合这里的需要;响应中是否包含必要的JS文件是一个集成测试问题;您可以使用 PageTester(通过遍历返回的 DOM)或在 Selenium 中(再次通过遍历客户端 DOM)来确定这一点。
事实上,理想情况下(这很困难),您可以在 Selenium 中编写测试,只有在必要的 JS 就位时才能通过。
鉴于 Tapestry 会在生产模式下将您的脚本聚合到 JS 堆栈中(这可能在 5.3 中以某种方式发生变化),您正在测试状态而不是行为。始终测试行为。
I still don't follow the need here; the question of whether necessary JS files are included in the response is an integration test issue; you can determine this using PageTester (by walking the returned DOM) or in Selenium (again, by walking the client DOM).
In fact, ideally (and this is difficult) you could write tests, in Selenium, that only pass if the necessary JS is in place.
Given that Tapestry will, in production mode, aggregate your scripts together into JS stacks (and that may change in some way in 5.3) you are testing state rather than behavior. Always test behavior.
这种方式似乎有效,尽管它依赖于一些可能改变的内部结构,并且可能会减慢速度。根据您的需要,您可能希望根据您关心的页面中设置的请求参数进行过滤(添加 RequestGlobals 作为参数并使用 set/getAttribute)。
更好的方法可能是提供您自己的 DocumentLinker,在添加脚本时捕获脚本。
将其添加到您的 AppModule:
在您的测试中:
执行页面
您可能必须更改任一侧以去除 Tapestry 添加的额外路径信息。
This way seems to work, although it relies on some internals that could change and it may slow things down a bit. Depending on your need, you might want to filter that based on a request parameter set in the pages you care about (add RequestGlobals as a parameter and use set/getAttribute).
A better way may be to provide your own DocumentLinker that captures the scripts as they get added.
Add this to your AppModule:
In your test:
execute the page
You might have to change either side to strip off the extra path information that Tapestry adds.