1 | const SCREENSHOT_PATH = "./screenshots/"; |
||
2 | const BINPATH = './node_modules/nightwatch/bin/'; |
||
3 | |||
4 | module.exports = { |
||
5 | "src_folders": [ |
||
6 | "tests/e2e" |
||
7 | ], |
||
8 | "output_folder": "./reports", |
||
9 | "test_runner" : { |
||
10 | "type" : "mocha" |
||
11 | }, |
||
12 | "selenium": { |
||
13 | "start_process": true, |
||
14 | "server_path": "./node_modules/nightwatch/bin/selenium.jar", |
||
15 | "host": "127.0.0.1", |
||
16 | "port": 4444, |
||
17 | "cli_args": { |
||
18 | "webdriver.chrome.driver" : "./node_modules/nightwatch/bin/chromedriver" |
||
19 | } |
||
20 | }, |
||
21 | "test_settings": { |
||
22 | "default": { |
||
23 | "launch_url" : "http://localhost:3003/abe/editor", |
||
24 | "silent": true, |
||
25 | "screenshots": { |
||
26 | "enabled": false, |
||
27 | "path": '' |
||
28 | }, |
||
29 | "globals": { |
||
30 | "waitForConditionTimeout": 3000 |
||
31 | }, |
||
32 | "desiredCapabilities" : { |
||
33 | "loggingPrefs": { |
||
34 | "browser": "ALL", |
||
35 | "driver": "ALL", |
||
36 | "performance": "ALL" |
||
37 | }, |
||
38 | "browserName" : "chrome", |
||
39 | "javascriptEnabled" : true, |
||
40 | "acceptSslCerts" : true, |
||
41 | "chromeOptions" : { |
||
42 | "perfLoggingPrefs": { |
||
43 | "traceCategories": "v8,blink.console,disabled-by-default-devtools.timeline" |
||
44 | }, |
||
45 | "args" : ["--no-sandbox", "start-fullscreen", "disable-web-security", "allow-running-insecure-content"] |
||
46 | } |
||
47 | } |
||
48 | }, |
||
49 | "chrome": { |
||
50 | "desiredCapabilities" : { |
||
51 | "loggingPrefs": { |
||
52 | "browser": "ALL", |
||
53 | "driver": "ALL", |
||
54 | "performance": "ALL" |
||
55 | }, |
||
56 | "browserName" : "chrome", |
||
57 | "javascriptEnabled" : true, |
||
58 | "acceptSslCerts" : true, |
||
59 | "chromeOptions" : { |
||
60 | "perfLoggingPrefs": { |
||
61 | "traceCategories": "v8,blink.console,disabled-by-default-devtools.timeline" |
||
62 | }, |
||
63 | "args" : ["--no-sandbox", "start-fullscreen", "disable-web-security", "allow-running-insecure-content"] |
||
64 | } |
||
65 | } |
||
66 | } |
||
67 | } |
||
68 | } |
||
69 | |||
70 | /* |
||
71 | // limit tests to one regex |
||
72 | "test_runner" : { |
||
73 | "type" : "mocha", |
||
74 | "options" : { |
||
75 | "grep" : /import/ |
||
76 | } |
||
77 | }, |
||
78 | */ |
||
79 | |||
80 | /* |
||
81 | loggingPrefs: { |
||
82 | 'browser': 'ALL', |
||
83 | 'driver': 'ALL', |
||
84 | 'performance': 'ALL' |
||
85 | }, |
||
86 | chromeOptions: { |
||
87 | perfLoggingPrefs: { |
||
88 | traceCategories: 'v8,blink.console,disabled-by-default-devtools.timeline' |
||
89 | }, |
||
90 | } |
||
91 | */ |
||
92 | /** |
||
93 | * selenium-download does exactly what it's name suggests; |
||
94 | * downloads (or updates) the version of Selenium (& chromedriver) |
||
95 | * on your localhost where it will be used by Nightwatch. |
||
96 | /the following code checks for the existence of `selenium.jar` before trying to run our tests. |
||
97 | */ |
||
98 | |||
99 | require('fs').stat(BINPATH + 'selenium.jar', function (err, stat) { // got it? |
||
100 | if (err || !stat || stat.size < 1) { |
||
101 | require('selenium-download').ensure(BINPATH, function(error) { |
||
102 | if (error) throw new Error(error); // no point continuing so exit! |
||
0 ignored issues
–
show
|
|||
103 | console.log('✔ Selenium & Chromedriver downloaded to:', BINPATH); |
||
0 ignored issues
–
show
|
|||
104 | }); |
||
105 | } |
||
106 | }); |
||
107 | |||
108 | function padLeft (count) { |
||
109 | return count < 10 ? '0' + count : count.toString(); |
||
110 | } |
||
111 | |||
112 | var FILECOUNT = 0; |
||
113 | /** |
||
114 | * The default is to save screenshots to the root of your project even though |
||
115 | * there is a screenshots path in the config object above! ... so we need a |
||
116 | * function that returns the correct path for storing our screenshots. |
||
117 | * While we're at it, we are adding some meta-data to the filename, specifically |
||
118 | * the Platform/Browser where the test was run and the test (file) name. |
||
119 | */ |
||
120 | function imgpath (browser) { |
||
121 | var a = browser.options.desiredCapabilities; |
||
122 | var meta = [a.platform]; |
||
123 | meta.push(a.browserName ? a.browserName : 'any'); |
||
124 | meta.push(a.version ? a.version : 'any'); |
||
125 | meta.push(a.name); // this is the test filename so always exists. |
||
126 | var metadata = meta.join('~').toLowerCase().replace(/ /g, ''); |
||
127 | return SCREENSHOT_PATH + metadata + '_' + padLeft(FILECOUNT++) + '_'; |
||
128 | } |
||
129 | |||
130 | module.exports.imgpath = imgpath; |
||
131 | module.exports.SCREENSHOT_PATH = SCREENSHOT_PATH; |
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.
Consider:
If you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42
will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.