When creating tests for my web application, I need to first simulate a login before proceeding with the rest of the tests to access inner pages. Currently, I am in the process of refactoring the code so that I can create an 'include' for common functions like logging in. However, when I move the code snippet below to a separate file and include it using require
, it does not function as expected.
For example, the following code successfully logs in and enables other functions when included in the same file above inner screen functions:
// Login screen, creating opportunity
this.LoginScreen = function(browser) {
browser
.url(Data.urls.home)
.waitForElementVisible('#login', 2000, false)
.click('#login')
// Remaining login steps...
Errors.checkForErrors(browser);
};
// Inner functions continue here sequentially
However, once I move the login code to a separate file called Logins.js
and include it at the top of the original test file using the correct path:
var Logins = require("../../lib/Logins.js");
The login simulation no longer works. Any suggestions? Should I consider removing the this.LoginScreen
function wrapper and calling it differently when executing it from the external file, or do I need to invoke it again within the original file in addition to the external require statement?
I have also attempted wrapping 'module.exports = {
' around the login function in the separate file without success.