protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Unable to find modules

Open cambiph opened this issue 12 years ago • 6 comments

Hello,

I'm starting out with protractor and everything works fine. But when I try out the page object structure, it seems that my pageobjects never seem to get loaded. The following stacktrace appears:

Failures:

  1. homepage encountered a declaration exception Message: Error: Cannot find module './pageobjects/loginPage.js' Stacktrace: Error: Cannot find module './pageobjects/loginPage.js' at require (module.js:380:17) at null. (C:\mlbdev\responsive\tests\test.js:5:21) at jasmine.Env.describe_ (C:\Users\pcambie1\AppData\Roaming\npm\node_modules\protractor\node_modules>>minijasminenode \lib\jasmine-1.3.1.js:907:21) at jasmine.Env.describe (C:\Users\pcambie1\AppData\Roaming\npm\node_modules\protractor\node_modules>minijasminenode
    lib\jasmine-1.3.1.js:892:15) at describe (C:\Users\pcambie1\AppData\Roaming\npm\node_modules\protractor\node_modules>minijasminenode\lib\jasmine- 1.3.1.js:652:27) at Object. (C:\mlbdev\responsive\tests\test.js:3:1)

Finished in 0.014 seconds 1 test, 1 assertion, 1 failure`

This is the page-object

var ptor;

var loginPage = function () {

    ptor       = protractor.getInstance();
    var driver = ptor.driver;

    this.usernameInput = ptor.driver.findelement(protractor.By.id('username'));
    this.passwordInput = ptor.driver.findelement(protractor.By.id('password'));
    this.loginButton   = ptor.driver.findelement(protractor.By.id('login_button_link'));
    this.header        = ptor.driver.findelement(protractor.By.tagName('h1'));

    this.login = function() {
        usernameInput.sendKeys('xxxxxxxx');
        passwordInput.sendKeys('xxxxxxx');
        loginButton.click();
    };
};

module.exports = new loginPage();

This is the actual test

var ptor;

describe('homepage', function() {

    var loginPage = require('./pageobjects/loginPage.js');

    beforeEach(function() {
        ptor = protractor.getInstance();
        ptor.driver.get('xxxxxxxxxx');
    });

    it('load page', function() {
        var header = ptor.driver.findElement(protractor.By.tagName('h1'));
        expect(header.getText()).toEqual('xxxxxx');
    });

    it('login', function() {
        loginPage.login;
        expect(loginPage.header.getText()).toEqual('xxxxxx');
    });
});

Any idea what I'm doing wrong here?

cambiph avatar Mar 20 '14 15:03 cambiph

Nevermind, I just found the problem. Instead of ./pageobjects/loginPage.js it should be ../pageobjects/loginPage.js

Two dots instead of one

cambiph avatar Mar 20 '14 15:03 cambiph

Just a random comment, I had the same issue, but capitalization was the problem. I renamed the page object file to lowercase and it worked. I had ../pageobjects/page.js and the file was named Page.js. Renamed to page.js and all was well.

ryanlitalien avatar Jan 20 '16 16:01 ryanlitalien

I was having the same issue, and ryanlitalien's recommendation to remove capitalization from the beginning of file and folder names worked for me as well

pinkninjajess avatar Feb 23 '16 15:02 pinkninjajess

I can confirm that this issue is still experienced. Name format should be camelCase

rcadia avatar Apr 29 '16 11:04 rcadia

Yeah, format should be camelCase e.g objectPage.

adnanghaffar07 avatar May 06 '16 02:05 adnanghaffar07

Any idea about the error message? practice shaurosenipalchoudhuri$ protractor conf.js [14:02:07] I/launcher - Running 1 instances of WebDriver [14:02:07] I/hosted - Using the selenium server at http://localhost:4444/wd/hub [14:02:08] E/launcher - Error: /Users/shaurosenipalchoudhuri/protractor/practice/src/specs/ysb-spec.js:6 import LoginPage from '../src/pages/login_page'; ^^^^^^^^^

SyntaxError: Unexpected identifier at new Script (vm.js:79:7) at createScript (vm.js:251:10) at Object.runInThisContext (vm.js:303:10) at Module._compile (internal/modules/cjs/loader.js:657:28) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) at tryModuleLoad (internal/modules/cjs/loader.js:538:12) at Function.Module._load (internal/modules/cjs/loader.js:530:3) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:22:18) [14:02:08] E/launcher - Process exited with error code 100 Subratos-Air:practice shaurosenipalchoudhuri$

subrato29 avatar Mar 09 '19 19:03 subrato29