Saurabh Shrivastava
Saurabh Shrivastava

Reputation: 1484

Cannot find Module in "protractor'

I am trying to get started with page object model in Protractor, but i am always getting "module not found" error. Please guide.

My Folder structure:

pages
   --- homePage.js
spec.js
conf.js

spec.js

'use strict';

var HomePage = require('pages/homePage.js');

describe('Login cases', function() {
  var page;
  it('Login without username & password', function() {
    page= new HomePage();
    page.mainLoginButton.click();
    page.popupLoginButton.click();
    expect(page.errMsgUsername.getText()).toEqual('Please enter valid Email or Mobile Number');
  });
});

conf.js

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

homePage.js

'use strict';

var HomePage = function () {
  browser.get('https://www.mobikwik.com');
  browser.driver.manage().window().maximize();
};

 HomePage.prototype = Object.create({}, {
    mainLoginButton: { get: function () { return by.id('qa-mbkLogin')); 

}},
    popupLoginButton: { get: function () { return by.xpath('//*

[@id="loginInfo"]/div[3]/p/button')); }},
    errMsgUsername: { get: function () { by.xpath('//*

[@id="loginInfo"]/div[1]/span')); }},
  }}
});

module.exports = HomePage;

I am always getting cannot find module error. What need to be changed?

Upvotes: 0

Views: 2045

Answers (1)

M. Hudson
M. Hudson

Reputation: 899

You should try:

var HomePage = require('./pages/homePage.js');

See if that helps.

You're also referencing "spec.js" in your config but the file is called "specs.js".

Upvotes: 1

Related Questions