I am trying to assert a PDF by extracting the text from it and then checking whether the text I want is present in the extracted text or not.
The code extracts the PDF properly. The problem is, irrespective of whether the PDF extracted text contains my text or not, the assertion passes.
I am not sure why this is failing.
public static boolean verifyPDFContent(String reqTextInPDF) throws IOException{
PDDocument doc = PDDocument.load(new File("User/download/test.pdf"));
PDFTextStripper pdfStripper = new PDFTextStripper();
String text = pdfStripper.getText(doc);
doc.close();
System.out.println(text);
Assert.assertTrue (text.equals (reqTextInPDF));
return text.contains(reqTextInPDF);
}
I call it through:
@Then("^I should verify$")
public void iShouldVerify() throws Throwable {
export_inspections.verifyPDFContent("z" );
}
returnstatement before the assertion call and thus renderingAssert.assertTrue()as dead code.Assert.assertTrue(text.contains(reqTextInPDF));