运行测试用例时出现节点错误“无法找到模块”

时间:2022-02-23 20:43:16

I'm new to node and nightwatch and I have followed all the Getting Started instructions from Installing node, npm, selenium stand alone, starting the selenium driver, I downloaded the chrome driver as well and have it in the same directory. I have created the conf file and a simple test case js. When I go to run the test case through Node Command Line, I keep getting an error:

我是node和nightwatch的新手,我已经按照安装节点,npm,selenium独立的所有Getting Started说明,启动了selenium驱动程序,我也下载了chrome驱动程序并将它放在同一目录中。我创建了conf文件和一个简单的测试用例js。当我通过Node Command Line运行测试用例时,我不断收到错误消息:

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

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

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"));

Test

测试

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

1 个解决方案

#1


0  

You specified "tests" in Nightwatch.js but test file is in "test" directory so a rename of the directory "test" to "tests" would at least fix that. Also, ,I think you should name the config file nightwatch.json

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

#1


0  

You specified "tests" in Nightwatch.js but test file is in "test" directory so a rename of the directory "test" to "tests" would at least fix that. Also, ,I think you should name the config file nightwatch.json

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