我已经成功测试了 fileUploadSimplehttp://www.primefaces.org/showcase/ui/fileUploadSimple.jsf使用 webElement.sendKeys() 方法。它不适用于自动上传
有没有办法测试 PrimeFaces fileUpload Autohttp://www.primefaces.org/showcase/ui/fileUploadAuto.jsf使用 Selenium WebDriver?
我也有喜欢你的发展。我将分享我的知识,但可能有更好的方法。
服务器端的jsf代码
<h:form id="lifeProposalEntryForm" enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{AddNewLifeProposalActionBean.handleProposalAttachment}"
mode="advanced" multiple="true" sizeLimit="3000000" update="customerEntryPanel attachmentDataList"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/" id="proposalAttachment"/>
</h:form>
客户端的 html 代码
<div id="lifeProposalEntryForm:proposalAttachment" class="ui-fileupload ui-widget">
<div class="ui-fileupload-buttonbar ui-widget-header ui-corner-top">
<span class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left ui-fileupload-choose" role="button">
<span class="ui-button-icon-left ui-icon ui-c ui-icon-plusthick"></span>
<span class="ui-button-text ui-c">Choose</span>
<input id="lifeProposalEntryForm:proposalAttachment_input" type="file" multiple="multiple" name="lifeProposalEntryForm:proposalAttachment_input">
</span>
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left ui-fileupload-upload" type="button" role="button">
<span class="ui-button-icon-left ui-icon ui-c ui-icon-arrowreturnthick-1-n"></span>
<span class="ui-button-text ui-c">Upload</span>
</button>
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left ui-fileupload-cancel" type="button" role="button">
<span class="ui-button-icon-left ui-icon ui-c ui-icon-cancel"></span>
<span class="ui-button-text ui-c">Cancel</span>
</button>
</div>
......
- 检索元素
lifeProposalEntryForm:proposalAttachment_input
by id
.
- Put/sendkey 文件(一个或多个文件)
- 检索元素
second button
of <div id="lifeProposalEntryForm:proposalAttachment"
.
- 单击按钮元素。
Java 中的 Selen 测试
webElement = driver.findElement(By.id("lifeProposalEntryForm:proposalAttachment_input"));
webElement.sendKeys("C:\\temp\\life\\life_1.jpg");
webElement = driver.findElement(By.xpath("//input[@type='file'and @id='lifeProposalEntryForm:proposalAttachment_input']"));
webElement= driver.findElement(By.xpath(".//*[@id='lifeProposalEntryForm:proposalAttachment']/div[1]/button[1]"));
webElement.click();
按照我提到的尝试。这对我来说是工作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)