[英]How do you test Wicket TextFields for read-only?
I want to test that my Wicket TextField
is set to readonly
. 我想测试将我的Wicket
TextField
设置为readonly
。 I have set up my WicketTester
but that just supports assertDisabled()
which is useless and fails in my case. 我已经设置了
WicketTester
但是仅支持assertDisabled()
,它是无用的,在我的情况下会失败。
I already tried tester.getComponentFromLastRenderedPage(compName).getString("readonly")
and tester.getComponentFromLastRenderedPage(compName).getMarkupAttributes().get("readonly")
which both sounded somewhat promising to me but failed to deliver. 我已经尝试过
tester.getComponentFromLastRenderedPage(compName).getString("readonly")
和tester.getComponentFromLastRenderedPage(compName).getMarkupAttributes().get("readonly")
,这听起来对我来说有些许希望,但未能交付。
Unfortunately, WicketTester
doesn't make it easy to do this very directly, but ... 不幸的是,
WicketTester
并不容易直接实现,但是...
Since AttributeModifier
is a behavior, you can call 由于
AttributeModifier
是一种行为,因此您可以调用
Component component = tester.getComponentFromLastRenderedPage("path");
List<IBehavior> behaviors = component.getBehaviors();
and pull the AttributeModifier
instances from the list (using instanceof
or isAssignableFrom
checks). 并从列表中拉出
AttributeModifier
实例(使用instanceof
或isAssignableFrom
检查)。 Then after some reflection to make things accessible, you can check whether there's one that matches your expected AttributeModifier
. 然后经过一番反思以使事情变得可访问,您可以检查是否存在与您期望的
AttributeModifier
匹配的对象。
This should be solvable by: 这可以通过以下方法解决:
TagTester ttest = tester.getTagByWicketId(compName);
assertNotNull(ttest.getAttribute(READONLY));
or something very similar. 或类似的东西。 I can't test this right now, so I can't be more specific.
我目前无法对此进行测试,因此我无法更加具体。 For more details check the JavaDocs of TagTester
有关更多详细信息,请检查TagTester的JavaDocs。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.