我有一个问题需要了解如何正确执行此操作,因为我在网上找不到任何解决方案。
我尝试测试 radio 选择并单击下载链接(奖励将断言下载的文件)。
我在面板中的代码是
exportXmlCartForm.add(createDownloadLink("downloadLinkId"));
final Form<Void> exportXmlCartForm = new Form<Void>("xmlCartFileExport");
final RadioGroup<String> group = new RadioGroup<String>("groupFileType", new sharedStringModel);
final Radio<String> radioPartslink = new Radio<String>("fileTypePARTSLINK", Model.of("pl"));
final Radio<String> radioPro = new Radio<String>("fileTypePRO", Model.of("pro"));
final Radio<String> radioCsv = new Radio<String>("fileTypeCSV", Model.of("csv"));
final Radio<String> radioXmlExport = new Radio<String>("fileXmlExport", Model.of("xml"));
group.add(radioPartslink, radioPro, radioCsv, radioXmlExport);
exportXmlCartForm.add(group);
这是我迄今为止的测试:
CartDTO cartDTO = new CartDTO();
IModel<CartDTO> cart = Model.of(cartDTO );
PopupPanel confirmPopup = new PopupPanel("1234");
FeedbackPanel feedbackPanel = new FeedbackPanel("12345678");
ShoppingCartFooterPanel p = new ShoppingCartFooterPanel("123", cart, confirmPopup, feedbackPanel);
testPage.setComponentToTest(p);
tester.startPage(testPage);
FormTester ft = tester.newFormTester("123:xmlCartFileExport", false);
ft.select("groupFileType", 3);
Object parstlinkSelected = p.get("xmlCartFileExport:groupFileType").getDefaultModelObject();
tester.clickLink("123:xmlCartFileExport:downloadCart");
我没有得到的是
- 如何在测试中做出不同的选择(以及如何验证这一点)
- 如何点击下载链接并验证我获得的文件。
如果有任何帮助,我将不胜感激。
谢谢
最佳答案
- 做出选择后,您需要
FormTester.submit()
。 - 使用
clickLink(..., false)
进行正常(即非 Ajax)点击。然后使用 (getBinaryContent()
和getHeader(String)
) 等tester.getLastResponse().get***()
方法进行断言。
关于java - WicketTester 选择 Radio Choice 并单击 DownloadLink,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36694884/