how to page-object in onReady.js
- Dominant language
- JavaScript
- Stars
- 7.2k
- Forks
- 621
- PR merge metrics
- No merged PRs in 30d
Description
I need to do a lot of replacement on different pages. So i made page-object file with vars and replacement functions and trying to connect it to onReady. But there is a problem with require external *.js - code inside require promis is not executed. Here is my code, onReady.js:
`module.exports = async (page, scenario, vp) => {
await require('./clickAndHoverHelper')(page, scenario);
if (scenario.label == "catalog-page") {
page.evaluateHandle(() => {
require(['/var/lib/jenkins/workspace/backstop-desktop/PageObjects/CatalogPage.js'], function (CatalogPage) {
console.log('This code has newer run');
let catalogPage = new CatalogPage();
catalogPage.replaceTopBanner('topBannerReplacementURL');
});
}
}
};`
CatalogPage.js:
`var CatalogPage = function() {
this.topBanner = document.querySelector('.bluefoot-wrapper img');
this.replaceTopBanner = (fakePicURL) => {
try {
topBanner.src = fakePicURL;
} catch (err) {
console.log('Top banner picture has not changed: ' + err);
}
}
this.itemsList = document.querySelectorAll('.grid-item');
};
module.exports = CatalogPage;`
Where I made a mistake? Is there any another way to include external libraries?
Contributor guide
Assessment
This issue has not been assessed yet.