Quality Products Quality Products - 1 month ago 6
AngularJS Question

Protractor page objects error

I'm building my angularjs protractor e2e test to the page objects pattern. I'm facing trouble with converting my script in to page object.

Here is my

conf.js


// conf.js
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['employee.js']
}


Here is my
employee.js


// spec.js
var EmpPageObject = require('./EmpPageObject.js');
describe('Protractor Demo App', function() {
it('should have a title', function() {

var empPageObject = new EmpPageObject();
empPageObject.get();

empPageObject.setName('mee');
empPageObject.setPassword('123');

});
});


Here is my
EmpPageObject.js


var EmpPageObject = function() {

var nameInput = element(by.model('login.user_name'));
var passwordInput = element(by.model('login.password'));
var addButton = element(by.css('.btn'));

this.get = function() {
browser.get('http://');
};

this.setName = function(name) {
nameInput.sendKeys(name);
};

this.setPassword = function(password) {
passwordInput.sendKeys(password);
};

addButton.click();

};


But, my script fails giving the following error.

Failures:
1) Protractor Demo App should have a title
Message:
Failed: EmpPageObject is not defined


This may be a dumb question. But, I cannot find the error since this is my first test. :)

Answer

Look like you copy-paste code from here https://github.com/angular/protractor/blob/f9c8a37f7dbec1dccec2dde0bd6884ad7ae3f5c7/docs/tutorial.md

describe('Protractor Demo App', function() {
  it('should have a title', function() {
    browser.get('http://juliemr.github.io/protractor-demo/');

    expect(browser.getTitle()).toEqual('Super Calculator');
  });
});

Here is protractor try to get resource and check - is it have title.

This function return true or false to make test. In your case, function return undefined, it is equal to false, test fail and you get error message.

Comments