-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnightwatch.conf.js
98 lines (93 loc) · 3.84 KB
/
nightwatch.conf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require('env2')('.env'); // optionally store your Evironment Variables in .env
const PKG = require('./package.json'); // so we can get the version of the project
const SCREENSHOT_PATH = './reports/screenshots/' + PKG.version + '/';
const BINPATH = './node_modules/nightwatch/bin/';
// we use a nightwatch.conf.js file so we can include comments and helper functions
const config = {
'src_folders': [
'test/e2e',// Where you are storing your Nightwatch e2e tests
],
'output_folder': './reports', // reports (test outcome) output by Nightwatch
'selenium': { // downloaded by selenium-download module (see readme)
'start_process': true, // tells nightwatch to start/stop the selenium process
'server_path': BINPATH + 'selenium.jar', // downloaded by selenium-download module (see below)
'log_path': '',
'host': '127.0.0.1',
'port': 4444, // standard selenium port
'cli_args': { // chromedriver is downloaded by selenium-download (see readme)
'webdriver.chrome.driver' : BINPATH + 'chromedriver', // also downloaded by selenium-download
},
},
'test_workers' : { 'enabled' : true, 'workers' : 'auto', }, // perform tests in parallel where possible
'test_settings': {
'default': {
'screenshots': {
'enabled': true, // if you want to keep screenshots
'path': SCREENSHOT_PATH, // save screenshots here
},
'globals': {
'waitForConditionTimeout': 5000, // sometimes internet is slow so wait.
},
'desiredCapabilities': { // use Chrome as the default browser for tests
'browserName': 'chrome',
},
},
'unittests' : {
'selenium' : {
'start_process' : false,
'start_session' : false,
},
},
'chrome': {
'desiredCapabilities': {
'browserName': 'chrome',
'javascriptEnabled': true, // turn off to test progressive enhancement
},
},
},
};
/**
* selenium-download does exactly what it's name suggests;
* downloads (or updates) the version of Selenium (& chromedriver)
* on your localhost where it will be used by Nightwatch.
/the following code checks for the existence of `selenium.jar` before trying to run our tests.
*/
require('fs').stat(BINPATH + 'selenium.jar', function (err, stat) { // got it?
console.log('getting that sweet sweet java');
if (err || !stat || stat.size < 1) {
require('selenium-download').ensure(BINPATH, function(error) {
console.log('in selium download cb');
if (error) {
console.error(error);
throw new Error(error); // no point continuing so exit!
}
console.log('✔ Selenium & Chromedriver downloaded to:', BINPATH); // eslint-disable-line
});
} else {
console.log('selenium.jar already exists');
}
});
function padLeft (count) {
return count < 10 ? '0' + count : count.toString();
}
var FILECOUNT = 0; // "global" screenshot file count
/**
* The default is to save screenshots to the root of your project even though
* there is a screenshots path in the config object above! ... so we need a
* function that returns the correct path for storing our screenshots.
* While we're at it, we are adding some meta-data to the filename, specifically
* the Platform/Browser where the test was run and the test (file) name.
*/
function imgpath (browser) {
var a = browser.options.desiredCapabilities;
var meta = [ a.platform, ];
meta.push(a.browserName ? a.browserName : 'any');
meta.push(a.version ? a.version : 'any');
meta.push(a.name); // this is the test filename so always exists.
var metadata = meta.join('~').toLowerCase().replace(/ /g, '');
return SCREENSHOT_PATH + metadata + '_' + padLeft(FILECOUNT++) + '_';
}
module.exports = config;
module.exports.imgpath = imgpath;
module.exports.url = process.env.URL || '0.0.0.0:3000'; // Ensure this is available in your .env file
module.exports.SCREENSHOT_PATH = SCREENSHOT_PATH;