Resources:JAVA, Selenium, TestNG, Maven
issue : I would like to validate a page which has pdf content only.
What I am able to assert as of now:
After clicking button from parent page I am able to redirect and switch the windowHandle from parent window
URL syntax is correct or not
URL is giving us 200 HTTP status code or not
Under DOM body this element is visible or not By.xpath("//*[@type='application/pdf']");
Note: My dev told me there are two kind of PDF (1) text based (2) Image based
I might have image based PDF that's why I am not able to read via PDFbox API (I guess).
Other API (PDFbox ) tried: below code is working with some other test PDF url but when I execute same code on my company PDF URL then I see "End of File error" , I tried to handle/google EOF error too but not got success.
driver.get("http://www.axmag.com/download/pdfurl-guide.pdf");
String getURL = driver.getCurrentUrl();
PDDocument doc = null;
BufferedInputStream file = null;
String output = null;
URL urlOfPdf = new URL(getURL);
BufferedInputStream fileToParse = new BufferedInputStream(urlOfPdf.openStream());
PDDocument document = PDDocument.load(fileToParse);
output = new PDFTextStripper().getText(document);
Assert.assertTrue(output.contains("some text"));
http://www.testingdiaries.com/selenium-webdriver-read-pdf-content/
EOF error trace:
java.io.IOException: Error: End-of-File, expected line
at org.apache.pdfbox.pdfparser.BaseParser.readLine(BaseParser.java:1124)
at org.apache.pdfbox.pdfparser.COSParser.parseHeader(COSParser.java:2589)
at org.apache.pdfbox.pdfparser.COSParser.parsePDFHeader(COSParser.java:2560)
at org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:219)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1222)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1122)
at com.ecompany.tests.RunOcrTest.validatePdfRunSummary1(RunOcrTest.java:135)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
What I want to know: How can we handle such scenario ? How to validate such test case ?
Thanks