当我从代码中调用Nightwatch.runTests方法时,我得到一个错误:
/ Connecting to 127.0.0.1 on port 4444...
POST /wd/hub/session - ECONNREFUSED
‼ Error connecting to 127.0.0.1 on port 4444.
_________________________________________________
Error: An error occurred while retrieving a new session: "Connection refused to 127.0.0.1:4444". If the Webdriver/Selenium service is managed by Nightwatch, check if "start_process" is set to "true".
at Socket.socketErrorListener (_http_client.js:407:9)
at emitErrorNT (internal/streams/destroy.js:84:8)
at processTicksAndRejections (internal/process/task_queues.js:80:21)文档here和here指出该方法接受两个参数: testSource和settings。作为testSource,我指定了包含测试的文件夹的路径。对于设置,我指定一个等同于nightwatch.json文件内容的json对象。如错误所述,参数"start_process“设置为true。
下面是要重现的代码:
const Nightwatch = require('nightwatch');
const seleniumServer = require('selenium-server-standalone-jar');
const chromedriver = require('chromedriver');
const settings = {
src_folders: ['tests'],
output_folder: 'reports',
detailed_output: true,
live_output: true,
selenium: {
start_process: false,
"server_path": seleniumServer.path,
"log_path": "logs",
"host": "127.0.0.1",
"port": 4444,
"cli_args": {
"trustAllSSLCertificates": true,
"webdriver.chrome.driver": chromedriver.path
}
},
test_settings: {
default: {
silent: true,
disable_error_log: false,
screenshots: {
enabled: false,
path: 'screenshots',
on_failure: true
},
},
chrome: {
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true,
chromeOptions: {
w3c: false
}
}
}
}
};
Nightwatch.runTests('tests', settings).then(function() {
// Tests finished
}).catch(function(err) {
// An error occurred
});在我的项目中,我使用了"nightwatch":"^ 1.3.6“和"selenium-server-standalone-jar":"^ 3.141.59”。
我还根据自动生成的文件“nightwatch.conf.js”的结构更改了设置对象:
const settings = {
src_folders: ['tests'],
output_folder: 'reports',
detailed_output: true,
live_output: true,
test_settings: {
default: {
disable_error_log: false,
launch_url: 'https://nightwatchjs.org',
screenshots: {
enabled: false,
path: 'screens',
on_failure: true
},
desiredCapabilities: {
browserName: 'chrome'
},
webdriver: {
start_process: true,
server_path: chromedriver.path
}
},
chrome: {
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
args: []
}
},
webdriver: {
start_process: true,
port: 9515,
server_path: chromedriver.path,
cli_args: []
}
},
selenium: {
selenium: {
start_process: true,
port: 4444,
server_path: seleniumServer.path,
cli_args: {
'webdriver.chrome.driver': chromedriver.path
}
}
},
'selenium.chrome': {
extends: 'selenium',
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
w3c: true
}
}
}
}
};但这并没有帮助,错误继续出现。
如果有人能帮助解决这个问题,我将不胜感激。
发布于 2020-06-29 17:45:11
你需要设置start_process: true,而不是start_process: false,你需要有效地设置w3c: true而不是w3c: false:
const settings = {
src_folders: ['tests'],
output_folder: 'reports',
detailed_output: true,
live_output: true,
selenium: {
start_process: true,
.
.
"cli_args": {
"trustAllSSLCertificates": true,
"webdriver.chrome.driver": chromedriver.path
}和
chrome: {
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true,
chromeOptions: {
w3c: true
}
}
}https://stackoverflow.com/questions/62635280
复制相似问题