I have created a test project using page object model. When I run, it creates "Cannot find module" error. I have tried several answers but didn't work.
Here is my code


exports.config = 
seleniumAddress: 'http://localhost:4444/wd/hub',
//specs: ['spec.js']
specs: ['./testSpec/**/*.js'],
jasmineNodeOpts: {
    defaultTimeoutInterval: 12000
onPrepare: function () {


var loginPageLocator = function()
var userName = Element(by.model('vm.username'));
var password = Element(by.model('vm.password'));
var signInButtonText = Element(by.buttonText('Sign in'));

this.get = function()


this.typeUserName = function(userName)


this.typePassword = function(password)


this.clickSignIn = function()


module.exports = new loginPageLocator();      


var logins = require('./../pageObjects/login.po.js');

describe('login to the system',function()
it('login as a dealer',function()
    var loginPage = new logins();



Here is the folder structure
folder structure


  • Please ensure npm, protractor version. Thanks! – Rohan Kalia Jun 6 '19 at 11:04
  • @Rohan I have define protractor and jasmine versions in package.json file – Joe Jun 6 '19 at 11:09

In your LoginTest.js , you have given incorrect reference of page object. change it to:

var logins = require('../../pageObjects/login.po.js');

and then you do not need to create a page object, instead you should directly use the object that you have created earlier like below


update your conf.js file, a sample is below:

    exports.config = {
        directConnect: true,
        capabilities: {
            'browserName': 'chrome'
        framework: 'jasmine',
        baseUrl: "http://url.com",
        specs: ['./*_specs.js'],

        onPrepare: function() {
            //create a global variable like below
global.variableName = "hello";
| improve this answer | |
  • still it gives the same error. If I imported the package/module correctly it should show methods inside it right? But I don't get suggestions – Joe Jun 6 '19 at 11:16
  • Please copy your LoginTest.js under testSpec folder and check. – Pankaj Dubey Jun 6 '19 at 11:22
  • path you mentioned works. Now I can access methods. New error appeared "Error: ReferenceError: Element is not defined" – Joe Jun 6 '19 at 11:33
  • Browser doesnt navigate to login page – Joe Jun 6 '19 at 11:34
  • That's because you haven't called the get method in your test script. call the get method in your it block of LoginTest.js – Pankaj Dubey Jun 6 '19 at 11:39

Check this, briefly explained here, and you can fix it https://youtu.be/idJHHxA02l8

| improve this answer | |
  • 1
    Please edit your answer to explain why the linked video answers the user's question. Please also indicate that the video is on your channel or you risk your answer being deleted as spam. – Kate Paulk Feb 21 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.