Verifying that a pdf is correctly displayed using new relic synthetics

  • 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) {
        .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("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)

  • (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.

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2