As I work on writing Protractor test cases using a page object, I am encountering difficulties when trying to use elements directly from the Page Object file within the spec file.
It seems like there might be some JavaScript nuances that I am missing, as my experience with JS is not extensive.
I want to utilize elements defined in the Page Object as shown below:
var PageObject = function()
{
var loginUsername = element(by.id('loginusername'));
//other methods
};
module.exports = PageObject;
I aim to use them in my spec file in the following manner:
var PageObject = require('./pageObject.page.js');
describe( ' Login page ', function(){
it('type something in the username field', function(){
var pageObject = new PageObject();
pageObject.get();
pageObject.loginUsername.sendKeys('Test');
});
});
While utilizing methods (such as get) works fine, directly using elements causes undefined errors.
I'm attempting to replicate functionality from examples like this one, where it should theoretically work.