运行测试用例时发生节点错误'找不到模块'
问题描述:
我是新来的节点和守夜人,我遵循安装节点,npm,硒单独的所有入门指示,启动硒驱动程序,我下载了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();
},
答
您在Nightwatch.js中指定了“测试”,但测试文件位于“test”目录中,因此将目录“test”重命名为“tests”至少可以解决此问题。此外,我认为你应该命名配置文件nightwatch.json
什么是测试文件路径名和你使用的是什么命令行? –
测试文件是在e2e /测试/ testpractice ...我试图运行它在节点js命令行 –
它看起来像这是一个节点问题,而不是一个守夜问题。 Nightwatch代码正在运行的堆栈轨迹中没有证据。我建议直接尝试Nightwatch,然后调试你的节点设置。示例:'node_modules/nightwatch/bin/nightwatch e2e/test/testpractice.js' –