使用Selenium WebDriver进行PrimeFaces fileUpload测试
我已经使用webElement.sendKeys()方法成功测试了fileUploadSimple http://www.primefaces.org/showcase/ui/fileUploadSimple.jsf 。 它不适用于自动上传
有没有办法用Selenium WebDriver测试PrimeFaces fileUploadAuto http://www.primefaces.org/showcase/ui/fileUploadAuto.jsf ?
我也喜欢你的发展。 我将分享我的知识,但可能有更好的方法。
服务方的jsf代码
客户端的HTML代码
- 通过
id
检索lifeProposalEntryForm:proposalAttachment_input
的元素。 - put / sendkey文件(一个或多个文件)
- 检索的
second button
的元素。 - 单击按钮元素。
在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();
试试我提到的。 这对我有用。