I want to test that my Wicket TextField
is set to readonly
. I have set up my WicketTester
but that just supports assertDisabled()
which is useless and fails in my case.
我想测试我的Wicket TextField设置为只读。我已经设置了我的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”)这两个听起来对我很有希望但未能实现。
2 个解决方案
#1
0
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). Then after some reflection to make things accessible, you can check whether there's one that matches your expected AttributeModifier
.
并从列表中提取AttributeModifier实例(使用instanceof或isAssignableFrom检查)。然后经过一些反思使得事物可以访问,你可以检查是否有一个匹配你预期的AttributeModifier。
#2
0
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
#1
0
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). Then after some reflection to make things accessible, you can check whether there's one that matches your expected AttributeModifier
.
并从列表中提取AttributeModifier实例(使用instanceof或isAssignableFrom检查)。然后经过一些反思使得事物可以访问,你可以检查是否有一个匹配你预期的AttributeModifier。
#2
0
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