question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"window.exists is not a function" after loading another page in a script

See original GitHub issue

Hi @garris,

i think there is a problem when a scenario script causes a new page to be loaded.

I’m trying to fill out a form on a page and submit the form afterwards (this works). The form actions brings me to a new page where the screenshot is supposed to get taken.

As soon as the new page is loaded and backstop tries to capture the screenshot it throws an exception:

COMMAND | Command `reference` ended with an error after [5.807s]
COMMAND | BackstopException: Account-Debitorwahl on 320-smallestPhone: Error: An error has occurred evaluating the script in the browser.TypeError: window.exists is not a function
    at window._backstopSelectorsExpMap.window._backstopSelectorsExp.reduce (<anonymous>:13:28)
    at Array.reduce (<anonymous>)
    at result (<anonymous>:11:72)
    at <anonymous>:22:9

I had a quick look around and realised that this function is provided by backstopTools.js which is injected after the initial goToUrl via Chromy. They are never re-injected when loading another page.

I quickly tried to manually inject backstopTools.js via chromy after the page load and that fixes the issue.

See my onReadyScript for this scenario below

const ConfigProvider = require('../../../_scripts/configProvider.js');
const path = require('path');

module.exports = (chromy, scenario, vp) => {
    const config = new ConfigProvider(scenario.url);

    chromy.type('input#email', config.getUsername());
    chromy.type('input#password', config.getPassword());
    chromy.click('form[action="/action/account/login"] input[type="submit"]', { waitLoadEvent: true });

    // Inject BackstopTools to provide helper methods needed for screenshots
    const BACKSTOP_TOOLS_PATH = path.join(__dirname, '../../../node_modules/backstopjs') + '/capture/backstopTools.js';
    chromy.inject('js', BACKSTOP_TOOLS_PATH);

    return chromy;
};

Backstop 3.0.19 Node 8.4.0 Chrome 61.0.3163.79 (Official Build) (64-bit) CentOS7

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
laubsaugercommented, Sep 20, 2017

I’m in the middle of preparing one, don’t worry.

0reactions
laubsaugercommented, Sep 25, 2017

@garris You assume correctly 😃

I’ve just tested 3.0.26 with my earlier hacks removed and it works flawlessly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

execute function after complete page load - javascript
I am using following code to execute some statements after page load. <script type="text/javascript"> window.onload = ...
Read more >
TypeError: "x" is not a function - JavaScript - MDN Web Docs
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value...
Read more >
How to Check If a Function Exists in Java Script - Code
Use an if Conditional Statement ; 13, if(window.doesntExist) { ; 14, console.log('the doesntExist() function exists'); ; 15, } ; 16, else{ ; 17...
Read more >
The 10 Most Common JavaScript Issues Developers Face
If you need help figuring out why your JavaScript isn't working, consult this list of the 10 most common JavaScript issues from a...
Read more >
External script doesn't always load when added to Nuxt ...
TypeError : window.jQuery is not a function at VueComponent.mounted (test-1.js:34). Refresh the page. Everything will load correctly.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found