【发布时间】:2017-05-12 14:38:24
【问题描述】:
大家好,我是 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();
});
}
任何想法可能发生的事情都会很棒。是否需要我展示更多内容让我知道。
【问题讨论】:
-
“知道会发生什么” ==> “找不到模块 '../support/action/openWebsite'”跨度>
-
你确定你的模块路径是正确的吗?
-
你应该使用 require,目前 node.js 本身不支持 import from 并且 babel & co 只将其转换为 require
-
我确定路径是好的
标签: javascript node.js webdriver-io