阅读使用Selenium WebDriver生成的PDF的最佳方法

时间:2018-09-03 21:08:47

标签: java selenium-webdriver

下午好,

我陷入了测试的最后一步,在插入一系列信息之后,该网站将生成pdf付款指南:

PDF generated at the end of the process

我需要捕获绿色的信息

下面是检查源代码时显示的代码:

<embed id="plugin" type="application/x-google-chrome-pdf" 

src="https://secweb.procergs.com.br/sng/javax.faces.resource/dynamiccontent.properties.xhtml?ln=primefaces&amp;v=5.3.17&amp;pfdrid=a9fc559a-bea3-4bc2-8234-5543c59715cc&amp;pfdrt=sc&amp;pfdrid_c=false&amp;uid=e483b7ac-35d3-429e-9c84-c5db516f1b8c" stream-url="blob:chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/3173c884-d121-48c6-b417-5972f907fe9e" headers="Cache-Control: no-cache, no-store, must-revalidate
Connection: Keep-Alive
Content-Encoding: gzip
Content-Language: pt-br
Content-Type: application/pdf; charset=UTF-8
Date: Mon, 03 Sep 2018 20:26:44 GMT
Expires: Mon, 8 Aug 1980 10:00:00 GMT
Keep-Alive: timeout=16, max=1021
Pragma: no-cache
Server: Apache
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-UA-Compatible: IE=Edge
" background-color="0xFF525659" top-toolbar-height="56" top-level-url="undefined">

根据我的逻辑,我什至不能从第一步开始,即通过一些唯一的文本来识别屏幕上PDF的存在:

if (driver0.getPageSource().contains("SECRETARIA DE MODERNIZAÇÃO ADMINISTRATIVA E DOS RECURSOS HUMANOS")) {
System.out.println("Located, we will capture the information ...");
} else {
System.out.println("Not found...");
}

使用PDFUtil库更新主题失败,我将其添加到该库中,但无法正常工作

这是我的主要考试:

try {
            PDFUtil pdfUtil = new PDFUtil();                
            pdfUtil.getText("C://64914273.pdf");
        } catch (Exception ex) {
            System.out.println(ex);
        }

控制台根本不返回任何内容

感谢那些能帮助我的人

2 个答案:

答案 0 :(得分:1)

一种选择是保存pdf并使用PDF库阅读内容并解析您要查找的文本。

看看PDFUtil和示例

http://www.testautomationguru.com/introducing-pdfutil-to-compare-pdf-files-extract-resources/

答案 1 :(得分:0)

我认为只有通过使用OCR库将信息包含在PDF中才能实现,但这通常非常脆弱。

我要做的是确定测试范围,以及是否可以将测试分开。

一个(自动)测试,检查单击“提交”时发送的信息或浏览器在HTTP请求中发送的信息是否正确。应该是像BrowserMob这样的简单代理,才能拦截请求。

第二次(手动)测试,检查PDF生成器在收到信息时是否正确显示了信息。

因此,一旦发送并检查了信息,您的自动测试就会结束,并且只有在给PDF生产者带来任何风险的情况下,才可以进行手动测试