4

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!

Marcel
  • 1,443
  • 2
  • 14
  • 24
Prototyped
  • 41
  • 2
  • 2
    So after more digging it seems there may be a bug with ChromeDriver retrieving the URL from the new Tab in headless mode. It only returns "about://blank" Now to just figure out a work around... If anyone has suggestions please let me know! – Prototyped Dec 05 '17 at 16:25

0 Answers0