I am trying to validate that a pdf contains a specific value, to do this , I click on a button that generates said pdf and opens it in a new tab. After this I switch to the new tab and then download the pdf and parse it. This all works if I am not using Chrome in headless mode. I have verified that the driver is successfully switching tabs. But when I try to get the URL or even attempt to run a test case that will be negative it just hangs. Using ChromeDriver 2.33.506106 and Selenium 3.6
static boolean verifyPDFText(String textToBeVal) {
try {
URL url = new URL(SeleniumDriver.getCurrentURL())
println url
InputStream file = SeleniumDriver.getStreamForUrl(SeleniumDriver.getCurrentURL());
PDDocument pdDoc = PDDocument.load(file)
String parsedText = new PDFTextStripper().getText(pdDoc)
pdDoc.close()
file.close()
println parsedText
if (parsedText.contains(textToBeVal)) {
assert true
} else {
"Unable to locate text: $textToBeVal"
assert false
}
} catch (MalformedURLException e) {
println "URL is Malforrmed"
println "Exception: $e"
assert false
} catch (IOException e) {
println "IOException:"
println "$e"
assert false
}
}
Any help would be greatly appreciated!