Node.js ERROR Cannot find Module

≯℡__Kan透↙ 提交于 2019-12-11 04:44:14

问题


Hey guys I'm new to JS and Node.js and I'm having trouble setting up a webdriverio project using cucumber and PageObject. And every time I try to run a test this error happens:

ERROR: Cannot find module '../support/action/openWebsite'
chrome
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/axelbarford/Desktop/Oktana-training-webdriverio/src/steps/LoginStepDef/loginStepsDef.js:1:1)
    at Module._compile (module.js:570:32)
    at loader (/usr/local/lib/node_modules/babel-register/lib/node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (/usr/local/lib/node_modules/babel-register/lib/node.js:154:7)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)

This is the loginStepsDef.js file where the openWebSite is being called:

 import openWebsite from '../support/action/openWebsite';
import LoginPage from '../pageobject/LoginPage/LoginPage';

module.exports = function given() {
    this.Given(
        /^I open salesforce login page$/,
            openWebsite
    );

    this.When(
        /^I set user "([^"]*)?" and password "([^"]*)?"$/, function(arg1,arg2) {
            LoginPage.open();
            LoginPage.username.setValue(arg1)
            LoginPage.password.setValue(arg2) 
        });

    this.And(
        /^I click the login button$/,function(){
            LoginPage.open();
            LoginPage.submit(); 
        });
}

Any idea what could be happening would be great. Do you need me to show something more let me know.


回答1:


Try with this :

 var openWebsite = require('../../support/action/openWebsite');
 var LoginPage = require('../../pageobject/LoginPage/LoginPage');


来源:https://stackoverflow.com/questions/43940412/node-js-error-cannot-find-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!