在尝试其他方法,请原谅我,这不是一个好方法。我已经开发了Nightwatch的端到端(E2E)测试代码,并且如果它是通过nodejs(node main.js)直接运行main.js,那么效果很好。
但是当我作为服务运行(sudo systemctl启动mytesting.service)时,出现以下错误:
Starting selenium server...
started - PID: 2949
[test / Job] Test Suite
Running: [0;32mDemo test Google
Error retrieving a new session from the selenium server[0m
Connection refused! Is selenium server started?
{ Error: socket hang up
at createHangUpError (_http_client.js:331:15)
at Socket.socketCloseListener (_http_client.js:363:23)
at emitOne (events.js:121:20)
at Socket.emit (events.js:211:7)
at TCP._handle.close [as _onclose] (net.js:554:12) code: 'ECONNRESET' }
配置-nightwatch.json
{
"output_folder": "temp",
"src_folders": ["/home/ubuntu/test/lib"],
"selenium": {
"start_process": true, /* tried false too*/
"server_path": "/home/ubuntu/test/bin/selenium-server-standalone-2.39.0.jar",
"log_path": "",
"port": 4444,
"cli_args": {
"webdriver.chrome.driver": "/home/ubuntu/test/bin/chromedriver"
}
},
"test_settings": {
"default": {
"launch_url": "http://localhost",
"selenium_port": 4444,
"selenium_host": "localhost",
"globals": {
"myGlobal": "testst"
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"marionette": true,
"acceptSslCerts": true,
"chromeOptions": {
"prefs": {
"download": {
"prompt_for_download": false,
"default_directory": "/home/ubuntu/test/downloads/"
}
},
"args": ["--no-sandbox", "window-size=1280,800"]
}
}
}
}
}
main.js
try {
const nightwatch = require('nightwatch');
const argv = {
config: 'nightwatch.json',
test: 'test.js',
env: 'default',
foo: 'bar',
};
const done = function() {
console.log('nightwatch complete');
}; // your callback function
var settings = {
globals: {
foo: 'one',
bar: 'two'
}
};
nightwatch.runner(argv, done, settings);
} catch (error) {
console.log('Exception:' + error.message);
}
欢迎提出建议,谢谢您的努力。