【问题标题】:Node error 'Cannot find module' when running test case运行测试用例时出现节点错误“找不到模块”
【发布时间】:2017-10-18 20:14:07
【问题描述】:

我是 node 和 nightwatch 的新手,我已经按照安装 node、npm、selenium 独立安装、启动 selenium 驱动程序中的所有入门说明进行操作,我还下载了 chrome 驱动程序并将其放在同一目录中。我已经创建了 conf 文件和一个简单的测试用例 js。当我通过节点命令行运行测试用例时,我不断收到错误:

Error: Cannot find module 'C:\Users\x203946\tests'

at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:383:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:496:3

Nightwatch.js

{
"src_folders": ["tests"],
"output_folder": "reports",
"custom_commands_path": "",
"custom_assertions_path": "",
"page_objects_path": "pages",
"globals_path": "globals",

"selenium": {
"start_process": true,
"server_path": "node_modules/selenium-standalone/.selenium/selenium-
server/",
"log_path": "./reports",
"host": "127.0.0.1",
"port": 4444,
"cli_args": {
"webdriver.chrome.driver": ""
}
},
"test_settings": {
"default": {
"launch_url": "https://localhost",
"selenium_port": 4444,
"selenium_host": "localhost",
"silent": true,
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}

Nightwatch.conf.js

require('babel-core/register');
const fs = require("fs");

module.exports = ((settings) => {
const seleniumFileName =
fs.readdirSync("node_modules/selenium-standalone/.selenium/selenium-
server/");
settings.selenium.server_path += seleniumFileName;
return settings;
})(require("./nightwatch.json"));

测试

module.exports = {
'Does not show the task list if there are no tasks'(client) {
client
.url('http://todomvc.com/examples/react/#/')
.waitForElementVisible('.header h1')
.expect.element('.main').to.not.be.present;
client.end();
},

【问题讨论】:

  • 测试文件路径名是什么,你使用的是什么命令行?
  • 测试文件在 e2e/test/testpractice ... 我正在尝试在 node js 命令行上运行它
  • 看起来这是节点问题而不是 Nightwatch 问题。堆栈跟踪中没有证据表明 Nightwatch 代码正在运行。我建议直接尝试 Nightwatch,然后调试您的节点设置。示例:node_modules/nightwatch/bin/nightwatch e2e/test/testpractice.js

标签: javascript node.js selenium testing nightwatch.js


【解决方案1】:

您在 Nightwatch.js 中指定了“测试”,但测试文件位于“测试”目录中,因此将目录“测试”重命名为“测试”至少可以解决这个问题。另外,我认为您应该将配置文件命名为 nightwatch.json

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    • 1970-01-01
    • 2018-04-07
    • 2019-08-28
    • 2020-12-21
    • 2015-10-09
    相关资源
    最近更新 更多