简体   繁体   English

使用Selenium WebDriver进行PrimeFaces fileUpload测试

[英]PrimeFaces fileUpload testing with Selenium WebDriver

I've successfully tested fileUploadSimple http://www.primefaces.org/showcase/ui/fileUploadSimple.jsf with webElement.sendKeys() method. 我已经使用webElement.sendKeys()方法成功测试了fileUploadSimple http://www.primefaces.org/showcase/ui/fileUploadSimple.jsf 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? 有没有办法用Selenium WebDriver测试PrimeFaces fileUploadAuto http://www.primefaces.org/showcase/ui/fileUploadAuto.jsf

I also have like your development. 我也喜欢你的发展。 I am going to share my knowledge but there might a better way. 我将分享我的知识,但可能有更好的方法。

jsf-code at servier side 服务方的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-code at client side 客户端的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>
......
  • Retrieve the element of lifeProposalEntryForm:proposalAttachment_input by id . 通过id检索lifeProposalEntryForm:proposalAttachment_input的元素。
  • Put/sendkey the file (one or more files) put / sendkey文件(一个或多个文件)
  • Retrieve the element of second button of <div id="lifeProposalEntryForm:proposalAttachment" . 检索<div id="lifeProposalEntryForm:proposalAttachment"second button的元素。
  • Click the button element. 单击按钮元素。

Selinium Testing in java 在java中的Selinium测试

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. 这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM