Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Verifying that a pdf is correctly displayed

javascript
bug
pdf
synthetics-script

#1

In my web application, I want a new relic script to go, click on a pdf link and 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

Hi @nolwenn.forey, what error are you seeing when you try to check the element? This would depend on how the PDF is rendered in the DOM but it may require switching contexts. Would you mind sharing a permalink to the monitor so I can take a look? :slight_smile:


#3

Hi @rdouglas

The error message is just TaskTimedOut: Task timed-out waiting for element to be located using: By(css selector, *[id="viewer"]). Here is the full stack:

Step 12: waitForElementPresent STARTED at 10142ms.
Step 12: waitForElementPresent FINISHED. It took 10051ms to complete.
Browser script execution FAILED.
Script execution failed: TimeoutError: Timed-out waiting for element to be located using: By(css selector, *[id="viewer"])
Wait timed out after 10050ms
TimeoutError: Timed-out waiting for element to be located using: By(css selector, *[id="viewer"])
Wait timed out after 10050ms
    at /opt/runtimes/4.0.0/node_modules/selenium-webdriver/lib/promise.js:2201:17
    at ManagedPromise.invokeCallback_ (/opt/runtimes/4.0.0/node_modules/selenium-webdriver/lib/promise.js:1376:14)
    at TaskQueue.execute_ (/opt/runtimes/4.0.0/node_modules/selenium-webdriver/lib/promise.js:3084:14)
    at TaskQueue.executeNext_ (/opt/runtimes/4.0.0/node_modules/selenium-webdriver/lib/promise.js:3067:27)
    at asyncRun (/opt/runtimes/4.0.0/node_modules/selenium-webdriver/lib/promise.js:2927:27)
    at /opt/runtimes/4.0.0/node_modules/selenium-webdriver/lib/promise.js:668:7
    at process._tickCallback (internal/process/next_tick.js:68:7)
From: Task: Timed-out waiting for element to be located using: By(css selector, *[id="viewer"])
    at scheduleWait (/opt/runtimes/4.0.0/node_modules/selenium-webdriver/lib/promise.js:2188:20)
    at ControlFlow.wait (/opt/runtimes/4.0.0/node_modules/selenium-webdriver/lib/promise.js:2517:12)
    at Driver.wait (/opt/runtimes/4.0.0/node_modules/selenium-webdriver/lib/webdriver.js:934:29)
    at Driver.value [as waitForElement] (/opt/runtimes/4.0.0/modules/synthetics-runner/lib/webdriver/index.js:650:21)
    at Driver.value [as waitForAndFindElement] (/opt/runtimes/4.0.0/modules/synthetics-runner/lib/webdriver/index.js:663:21)
    at $browser.getCapabilities.then.then.then.then.then.then.then.then.then.then.then.then.then.then (eval at JobResource.getScriptFn (/opt/runtimes/4.0.0/modules/synthetics-runner/lib/job-resource/index.js:76:19), <anonymous>:144:29)
    at ManagedPromise.invokeCallback_ (/opt/runtimes/4.0.0/node_modules/selenium-webdriver/lib/promise.js:1376:14)
    at TaskQueue.execute_ (/opt/runtimes/4.0.0/node_modules/selenium-webdriver/lib/promise.js:3084:14)
    at TaskQueue.executeNext_ (/opt/runtimes/4.0.0/node_modules/selenium-webdriver/lib/promise.js:3067:27)
    at asyncRun (/opt/runtimes/4.0.0/node_modules/selenium-webdriver/lib/promise.js:2927:27)

Also, since the pdf opens in a new page and that I am switching to this new page, doesn’t that automatically switch the context too?

As for the permalink, since I don’t know what information it will reveal to you, I rather not share it. But maybe I could give you the relevant information instead?


#4

That would depend on how the PDF is loaded, it may be in a different frame in the DOM, but this error would indicate that’s not the case. I am a New Relic employee so it is safe to share a permalink to the monitor, however I understand if you would rather not. Instead, it would be great if you had a publicly accessible link to the site you are using, if not a snippet of the source code.

You could also try using the Katalon script Recorder which allows you to record a script while clicking through a website and export it to Synthetics. This may give a better idea of what locator to use :slight_smile: