"window.exists is not a function" after loading another page in a script
See original GitHub issueHi @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:
- Created 6 years ago
- Comments:13 (10 by maintainers)
Top GitHub Comments
I’m in the middle of preparing one, don’t worry.
@garris You assume correctly 😃
I’ve just tested 3.0.26 with my earlier hacks removed and it works flawlessly.