本文介绍了使用Selenium WebDriver进行PrimeFaces fileUpload测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经成功测试了fileUploadSimple
与webElement.sendKeys()方法。它不适用于自动上传
有什么方法可以测试PrimeFaces fileUploadAuto ?
解决方案
我也喜欢你的发展。我将分享我的知识,但可能有更好的方法。
jsf代码在服务器端
或更多的文件)
webElement = driver.findElement(By.id(lifeProposalEntryForm:proposalAttachment_input));
webElement.sendKeys(C:\\\\\\\\\\\ 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();
请尝试我提到的。这是我的工作。
I've successfully tested fileUploadSimple http://www.primefaces.org/showcase/ui/fileUploadSimple.jsfwith webElement.sendKeys() method. It doesn't work with Auto upload
Is there any way to test PrimeFaces fileUploadAuto http://www.primefaces.org/showcase/ui/fileUploadAuto.jsf with Selenium WebDriver?
解决方案
I also have like your development. I am going to share my knowledge but there might a better way.
jsf-code at servier side
<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-code at client side
<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> ......
- Retrieve the element of lifeProposalEntryForm:proposalAttachment_input by id.
- Put/sendkey the file (one or more files)
- Retrieve the element of second button of <div id="lifeProposalEntryForm:proposalAttachment".
- Click the button element.
Selinium Testing in java
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();
Try as I mention. It is work for me.
这篇关于使用Selenium WebDriver进行PrimeFaces fileUpload测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!