Currently, I am using Selenium WebdriverJs along with Mocha to conduct tests on Sauce Labs via Travis CI. After isolating the issue without any project dependencies, I am seeking help.
The interesting observation is that defining an additional object with properties for visiting a URL and scrolling down within the test script itself works perfectly fine. You can find the link to the test script here.
If we set it up like this:
var eventPage = {
init: function(webdriver) {
this.driver = webdriver;
},
visit: function(url) {
return this.driver.get(url);
},
scrollDown: function() {
function scroll() {
window.scrollTo(0, arguments[0]);
}
return this.driver.executeScript(scroll, 800);
}
};
var driver = // Initialize the selenium driver
eventPage.init(driver)
eventPage.visit('http://reddit.com')
eventPage.scrollDown().then(function() {
console.log("This operates smoothly on Sauce Labs");
});
This setup performs well on Sauce Labs. The Travis build link is here, and the Sauce Build link is here.
However, when I create a file named eventPage.js and import it with all the above functions into the test script, it stops working. The link to that specific file is here, and the test script link is here.
module.exports = {
init: function(webdriver) {
this.driver = webdriver;
},
visit: function(url) {
return this.driver.get(url);
},
scrollDown: function() {
function scroll() {
window.scrollTo(0, arguments[0]);
}
return this.driver.executeScript(scroll, 800);
}
};
Subsequently, importing it into my test script yields an error,
var eventPage = src('path of the above file');
var driver = // Initialize the selenium driver
eventPage.init(driver)
eventPage.visit('http://reddit.com');
eventPage.scrollDown().then(function() {
console.log("This results in an error");
});
This error manifests on Sauce Labs. The failed build link on Travis CI is available here, while the corresponding Sauce Labs link is accessible here. Notably, both methods work flawlessly on my local machine. Any assistance would be greatly appreciated, as I have dedicated considerable time to resolve this issue. Thank you and have a pleasant day!