javascript - Node.js 错误找不到模块

标签 javascript node.js webdriver-io

大家好,我是 JS 和 Node.js 新手,我在使用 cucumber 和 PageObject 设置 webdriverio 项目时遇到问题。每次我尝试运行测试时都会发生此错误:

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)

这是调用 openWebSite 的 loginStepsDef.js 文件:

 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(); 
        });
}

任何关于可能发生的事情的想法都会很棒。您需要我展示更多内容吗?请告诉我。

Tree

最佳答案

试试这个:

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

关于javascript - Node.js 错误找不到模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43940412/

相关文章:

javascript - 未命名函数 JavaScript 的递归函数调用

javascript - 未应用欧芹选项

node.js - 如何在 Vue.js 中使用 dotenv

javascript - Node.js:为什么我的预期值没有在 'catch' 子句的 'try-catch' block 中返回?

javascript - 使用 JavaScript 在 Safari 中下载文件

javascript - 使用 Facebook Messenger 设置基本模板卡片时遇到问题

node.js - Node sass : File to import not found or unreadable: ./node_modules/

javascript - 如何使用 Winston v2 过滤消息?

javascript - 在 WebdriverIO 上执行 TestRunner 失败

javascript - 更改 appium 设置以在模拟器中不具有应用程序的新状态