Java 使用Selenium WebDriver进行PrimeFaces文件上载测试

Java 使用Selenium WebDriver进行PrimeFaces文件上载测试,java,jsf,file-upload,primefaces,selenium-webdriver,Java,Jsf,File Upload,Primefaces,Selenium Webdriver,我已经成功地测试了fileUploadSimple 使用webElement.sendKeys()方法。它不适用于自动上载 有没有办法用Selenium WebDriver测试PrimeFaces fileUploadAuto?我也喜欢你的开发。我打算分享我的知识,但可能有更好的方法 servier端的jsf代码 <h:form id="lifeProposalEntryForm" enctype="multipart/form-data"> <p:fileUpload

我已经成功地测试了fileUploadSimple 使用webElement.sendKeys()方法。它不适用于自动上载


有没有办法用Selenium WebDriver测试PrimeFaces fileUploadAuto?

我也喜欢你的开发。我打算分享我的知识,但可能有更好的方法

servier端的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>

如我所说,试试看。这是我的工作

你想在测试中断言什么?我断言上传图像的字节数组等于实际图像的字节数组。官方网站声明fileUploadAuto组件如下:“启用自动上载时,一旦选择文件,上载过程即开始”。
<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>
......
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();