In this post I will explain the procedure to verify PDF file content using java webdriver. As some time we need to verify content of web application pdf file, opened in browser.
Use below code in your test scripts to get pdf file content.
Hope this post will help to verify web application PDF content.
Use below code in your test scripts to get pdf file content.
//get current urlpdf file url
URL url = new URL(driver.getCurrentUrl());
//create buffer reader object
BufferedInputStream fileToParse = new
BufferedInputStream(url.openStream());
PDFParser pdfParser = new
PDFParser(fileToParse);
pdfParser.parse();
//save pdf text into strong variable
String pdftxt = new
PDFTextStripper().getText(pdfParser.getPDDocument());
//close PDFParser object
pdfParser.getPDDocument().close();
After applying above code, you can store all pdf file content
into “pdftxt” string variable. Now you can verify string by giving in put. As if you want to verify “Selenium Or Webdiver”
text. Use below code.
Assert.assertTrue(pdftxt.contains(“Selenium
Or Webdiver”))
Thanks
ReplyDeleteeclipse is not identifying " PDFParser pdfParser = new PDFParser(fileToParse);"
ReplyDeleteDo we need to import any special Jars for this.
yes you can download pdfbox-app-1.7.1.jar file for this
DeleteThere is a problem in my side can u guess this ?
ReplyDeletejava.io.IOException: Error: End-of-File, expected line
at org.apache.pdfbox.pdfparser.BaseParser.readLine(BaseParser.java:1475)
at org.apache.pdfbox.pdfparser.PDFParser.parseHeader(PDFParser.java:308)
at org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:172)
at com.popup.execute.ExecuteTest.testPdfVerification(ExecuteTest.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
I am also getting Error: End-of-File, expected line. Let me know if you have any solution.
ReplyDeletePDFParser pdfParser = new PDFParser(fileToParse) : I am getting compliation error for this line :
ReplyDeleteThe constructor PDFParser(BufferedInputStream) is undefined
I have used this pdfbox-app-1.7.1.jar file .
Even I am facing the same issue
DeleteDid u get the solution Shruti
DeleteI am also getting 'End-of-File, expected line' error.
ReplyDeleteI am also getting 'End-of-File, expected line' error.
ReplyDeleteI am also getting 'End-of-File, expected line' error. Can someone tell me the solutions
ReplyDeleteAny help appreciated
ReplyDeleteAny help would be apprecaited
ReplyDelete