Help please to find an error. I'm learning Protractor and try to create a simple test with Page Object.
//login_pageObject.js
let loginContainer = function() {
this.usernameInput = $("input.login-form-01");
this.passwordInput = $("input#login-form-02");
this.loginBtn = $("input.btn");
this.get = function() {
browser.get("https://www.cosmedicalsupplies.com/login.html");
};
this.setUsername = function(username) {
usernameInput.sendKeys(username);
};
this.setPassword = function(password) {
passwordInput.sendKeys(password);
};
this.clickOnLoginBtn = function() {
loginBtn.click();
};
};
module.exports = new loginContainer();
And
//login.js
let loginPage = require('../page_objects/login_pageObject.js');
describe('login_logout autotests', () => {
beforeEach(() => {
browser.ignoreSynchronization = true;
});
it("should sign in", () => {
loginPage.get();
loginPage.setUsername("test1");
loginPage.setPassword("test2");
loginPage.clickOnLoginBtn();
//expect.....
});
});
So, when I run this code, I have a "Failed: usernameInput is not defined" error. Where is mistake?
You need to refer to it as this.usernameInput
.