// @ts-ignore
const chromedriver = require('chromedriver');
const seleniumServer = require('selenium-server');
const config = {
// we use a nightwatch.conf.js file so we can include comments and helper functions
src_folders: [
'src/tests/functionaltest', // we use '/test' as the name of our test directory by default. So 'test/e2e' for 'e2e'.
],
page_objects_path: 'src/tests/page-objects',
output_folder: './node_modules/nightwatch/reports', // reports (test outcome) output by Nightwatch
custom_commands_path: 'src/tests/commands',
selenium: {
start_process: true,
server_path: seleniumServer.path,
log_path: '',
host: '127.0.0.1',
port: 4444,
cli_args: {
'webdriver.chrome.driver': chromedriver.path,
},
},
test_workers: { enabled: true, workers: 'auto' }, // perform tests in parallel where possible
test_settings: {
default: {
webdriver: {
start_process: true,
server_path: chromedriver.path,
port: 4444,
cli_args: ['--port=4444'],
},
launch_url: 'http://localhost:3000',
selenium_port: 4444,
selenium_host: '127.0.0.1',
silent: true,
capabilities: {
configuration: {
_comment: 'Configuration for Node',
cleanUpCycle: 2000,
timeout: 30000,
port: 5555,
host: '127.0.0.1',
register: true,
hubPort: 4444,
maxSession: 5,
},
},
desiredCapabilities: {
browserName: 'chrome',
seleniumProtocol: 'WebDriver',
chromeOptions: {
w3c: false,
args: [
'--enable-features=NetworkService,NetworkServiceInProcess',
'--headless',
'--disable-gpu',
'--no-sandbox',
'--disable-dev-shm-usage',
'--window-size=1920,1080',
],
},
},
screenshots: {
enabled: true,
path: './reports/nightwatchTests/screenshots',
on_failure: true,
on_error: true,
},
use_xpath: false,
},
local: {
launch_url: 'http://localhost:3000',
selenium_port: 4444,
selenium_host: '127.0.0.1',
silent: true,
globals: {
waitForConditionTimeout: 15000, // Default timeout, 15 seconds
},
desiredCapabilities: {
browserName: 'chrome',
platform: 'ANY',
seleniumProtocol: 'WebDriver',
chromeOptions: {
w3c: false,
args: [
'--enable-features=NetworkService,NetworkServiceInProcess',
'--headless',
'--disable-gpu',
'--no-sandbox',
'--disable-dev-shm-usage',
'--window-size=1920,1080',
],
},
javascriptEnabled: true,
acceptSslCerts: true,
},
},
Hi, I'm trying to convert a bash script that invokes nightwatch to using programmatic API, and when I'm running it, the webdriver isn't starting and I can't figure out why.
config:
{
output_folder: 'nightwatch_output',
webdriver: {
start_process: true,
port: 9515,
server_path: '/usr/local/bin/chromedriver',
cli_args: [
'--port=9515',
'--log-path=nightwatch_output/chromedriver-2021-07-23T00:55:10.479Z.log'
]
},
test_settings: {
default: {
desiredCapabilities: [Object],
globals: [Object],
launch_url: 'redacted',
screenshots: [Object]
}
},
globals: {
asyncHookTimeout: 90000,
retryAssertionTimeout: 30000,
waitForConditionTimeout: 30000
},
src_folders: [ 'test' ]
}
Code:
(async () => {
const runner = Nightwatch.CliRunner();
await runner.setup(config).startWebDriver();
try {
runner.runTests();
} catch (err) {
await runner.stopWebDriver();
}
})();
output:
==========================
⠋ Connecting to localhost on port 9515...
POST /session - ECONNREFUSED
⚠ Error connecting to localhost on port 9515.
_________________________________________________
TEST FAILURE: 1 error during execution; 0 tests failed, 0 passed (123ms)
Error: An error occurred while retrieving a new session: "Connection refused to 127.0.0.1:9515". If the Webdriver/Selenium service is managed by Nightwatch, check if "start_process" is set to "true".
You could also use Nightwatch default config which would save you from all the configuration
That seems like a silly suggestion.
Additional feedback:
when starting the runner, I don't think it should resolve if there are no instances to start. Rejecting due to no instances would be best, but at least have a warning logged that there are no instances created (and why) would save a lot of time in debugging.
Hi.. I am using nightwatch API as a node service. I found that over the time, the memory is keep increasing. When I profiled the node app, I see the results are not being cleared from memory and all the loaded scenarios as modules are in memory in the form of strings. Is there a way to unload the scenario when a test is completed?
Also is there a way to store the results as JSON file.. I am using the reporter callback in globals to get the results and saving it as JSON. But when there are many tests, the results object is huge and it is crashing the server when saving it to file system (Probably during stringify. I am using BFJ library to stringify the object asynchronously). Any ideas to reduce the report size?
Thanks
var HtmlReporter = require('nightwatch-html-reporter');
/ Same options as when using the built in nightwatch reporter option /
var reporter = new HtmlReporter({
openBrowser: true,
reportsDirectory: __dirname + '/reports/'
});
module.exports = {
write : function(results, options, done) {
reporter.fn(results, done);
}
};