0

I have created scripts in new relic synthetics that verify the web application is still behaving correctly.

This script does the following things:

  • go to the specific page
  • click on a pdf link
  • verify that the pdf is correctly displayed

To do that, here is a snippet of my script:

    .then(() => { // Here I click on my link
            logger.log(10, "clickElement link=The link text");
            return $browser.waitForAndFindElement(By.linkText("The link text"), DefaultTimeout)
                .then(function (el) {
                    el.click();
                })
        })
    .then(() => { // I switch to the newly open pdf windows
            // switchTo window [1] as the new window
            logger.log(11, "switch window ");
            return $browser.sleep(1000)
                .then(function() {
                    return $browser.getAllWindowHandles()
                })
                .then(handles => {
                    return $browser.switchTo().window(handles[1])
                })
        })


    .then(() => {  // I verify that the pdf is displayed by looking for the id "viewer"
            logger.log(12, "waitForElementPresent");
            return $browser.waitForAndFindElement(By.id("viewer"), DefaultTimeout)

        })

The problem is, new relic doesn’t find the id “viewer” even though the screenshot shows that the pdf is correctly displayed. I also tried to us $browser.waitForAndFindElement(By.class("page"), DefaultTimeout) instead, but I have the same error.

Any thought?

(Please note that my way of verifying the pdf display works with selenium+java)

2
  • 1
    My way of veryfing pdfs was to download them as file and then parse their content using external libraries. The advantages are that the downloaded file is the same regardless of which browser was used to download it. The disadvantages are that pdfs cannot be reliably converted to html or anything that would make it easy to verify their layout. In my case the text content was enough. Also, doing so is relatively easy in java, and you say you have no problem in java anyway, so there you have it.
    – JockX
    Commented Sep 4, 2019 at 14:10
  • I wrote an answer about a related issue (verifying pdf using selenium + java). I believe it could help future reader, so here it goes Commented Nov 12, 2019 at 9:32

1 Answer 1

1

(OP here)

I finally found out why this way of verifying pdf wasn't working.

I made the false assumption that every platform (Firefox, Chrome, Edge, Safari, etc...) was displaying pdf the same way. But, this isn't the case.

So, my code was working fine using Selenium + Java because I was also using Firefox driver.

However, new relic synthetics doesn't seem to be using Firefox (maybe they are using Chrome?) which explains why my code didn't work.

I didn't try to fix this code. Nonetheless, I write an answer here that explain how to verify pdf using selenium + java in a multiplatform way.

The basic idea of the answer is:

  1. Download the pdf

  2. Use java to verify the pdf data

I hope this might help future readers.

Not the answer you're looking for? Browse other questions tagged or ask your own question.