Skip to content

Commit 6999b48

Browse files
feat: Upgraded Nightwatch to 2.0, updated distribued config (#6520)
Co-authored-by: Haoqun Jiang <[email protected]>
1 parent e829a04 commit 6999b48

File tree

5 files changed

+368
-111
lines changed

5 files changed

+368
-111
lines changed

packages/@vue/cli-plugin-e2e-nightwatch/__tests__/nightwatchPlugin.spec.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ describe('nightwatch e2e plugin', () => {
9999
testSettings = JSON.parse(testSettings)
100100

101101
expect(testSettings.parallel_mode).toStrictEqual(true)
102-
expect(testSettings.test_workers).toStrictEqual(true)
102+
expect(testSettings.test_workers).toStrictEqual({
103+
enabled: true,
104+
workers: 'auto'
105+
})
103106

104107
expect(Object.keys(results.modules).sort()).toEqual([
105108
'test', 'test-with-pageobjects'

packages/@vue/cli-plugin-e2e-nightwatch/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ async function loadNightwatchConfig (rawArgs, api) {
127127

128128
process.env.VUE_NIGHTWATCH_USER_OPTIONS = JSON.stringify(userOptions || {})
129129

130-
rawArgs.push('--config', require.resolve('./nightwatch.config.js'))
130+
rawArgs.push('--config', require.resolve('./nightwatch.conf.js'))
131131
}
132132
}
133133

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,360 @@
1+
// Autogenerated by Nightwatch
2+
// Refer to the online docs for more details: https://nightwatchjs.org/gettingstarted/configuration/
3+
4+
const path = require('path')
5+
const deepmerge = require('deepmerge')
6+
7+
const Services = {}
8+
loadServices()
9+
const VUE_DEV_SERVER_URL = process.env.VUE_DEV_SERVER_URL
10+
const BROWSERSTACK_USER = process.env.BROWSERSTACK_USER
11+
const BROWSERSTACK_KEY = process.env.VUE_DEV_SERVER_URL
12+
const userOptions = JSON.parse(process.env.VUE_NIGHTWATCH_USER_OPTIONS || '{}')
13+
const concurrentMode = process.env.VUE_NIGHTWATCH_CONCURRENT === '1'
14+
const useSelenium = process.env.VUE_NIGHTWATCH_USE_SELENIUM === '1'
15+
const startHeadless = process.env.VUE_NIGHTWATCH_HEADLESS === '1'
16+
const chromeArgs = []
17+
const geckoArgs = []
18+
19+
if (startHeadless) {
20+
chromeArgs.push('headless')
21+
geckoArgs.push('--headless')
22+
}
23+
24+
// _ _ _ _ _ _ _
25+
// | \ | |(_) | | | | | | | |
26+
// | \| | _ __ _ | |__ | |_ __ __ __ _ | |_ ___ | |__
27+
// | . ` || | / _` || '_ \ | __|\ \ /\ / / / _` || __| / __|| '_ \
28+
// | |\ || || (_| || | | || |_ \ V V / | (_| || |_ | (__ | | | |
29+
// \_| \_/|_| \__, ||_| |_| \__| \_/\_/ \__,_| \__| \___||_| |_|
30+
// __/ |
31+
// |___/
32+
33+
const defaultSettings = {
34+
// An array of folders (excluding subfolders) where your tests are located;
35+
// if this is not specified, the test source must be passed as the second argument to the test runner.
36+
src_folders: ['tests/e2e/specs'],
37+
38+
// See https://nightwatchjs.org/guide/working-with-page-objects/
39+
page_objects_path: 'tests/e2e/page-objects',
40+
41+
// See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands
42+
custom_commands_path: 'tests/e2e/custom-commands',
43+
44+
// See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-assertions
45+
custom_assertions_path: 'tests/e2e/custom-assertions',
46+
47+
// See https://nightwatchjs.org/guide/#external-globals
48+
globals_path: path.resolve('tests/e2e/globals.js'),
49+
50+
output_folder: 'tests/e2e/reports',
51+
52+
webdriver: {},
53+
54+
test_workers: {
55+
enabled: concurrentMode,
56+
workers: 'auto'
57+
},
58+
59+
test_settings: {
60+
default: {
61+
disable_error_log: false,
62+
launch_url: `${VUE_DEV_SERVER_URL}`,
63+
64+
screenshots: {
65+
enabled: false,
66+
path: 'screens',
67+
on_failure: true
68+
},
69+
70+
desiredCapabilities: {
71+
browserName: 'firefox'
72+
},
73+
74+
webdriver: {
75+
start_process: true,
76+
server_path: Services.geckodriver ? Services.geckodriver.path : ''
77+
}
78+
},
79+
80+
safari: {
81+
desiredCapabilities: {
82+
browserName: 'safari',
83+
alwaysMatch: {
84+
acceptInsecureCerts: false
85+
}
86+
},
87+
webdriver: {
88+
start_process: true,
89+
server_path: '/usr/bin/safaridriver'
90+
}
91+
},
92+
93+
firefox: {
94+
desiredCapabilities: {
95+
browserName: 'firefox',
96+
alwaysMatch: {
97+
// Enable this if you encounter unexpected SSL certificate errors in Firefox
98+
// acceptInsecureCerts: true,
99+
'moz:firefoxOptions': {
100+
args: geckoArgs
101+
}
102+
}
103+
},
104+
webdriver: {
105+
start_process: true,
106+
server_path: Services.geckodriver ? Services.geckodriver.path : '',
107+
cli_args: [
108+
// very verbose geckodriver logs
109+
// '-vv'
110+
]
111+
}
112+
},
113+
114+
chrome: {
115+
desiredCapabilities: {
116+
browserName: 'chrome',
117+
'goog:chromeOptions': {
118+
// More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/
119+
//
120+
// w3c:false tells Chromedriver to run using the legacy JSONWire protocol (not required in Chrome 78)
121+
w3c: true,
122+
args: chromeArgs
123+
}
124+
},
125+
126+
webdriver: {
127+
start_process: true,
128+
server_path: Services.chromedriver ? Services.chromedriver.path : '',
129+
cli_args: [
130+
// --verbose
131+
]
132+
}
133+
},
134+
135+
edge: {
136+
desiredCapabilities: {
137+
browserName: 'MicrosoftEdge',
138+
'ms:edgeOptions': {
139+
w3c: true,
140+
// More info on EdgeDriver: https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/capabilities-edge-options
141+
args: [
142+
// '--headless'
143+
]
144+
}
145+
},
146+
147+
webdriver: {
148+
start_process: true,
149+
// Download msedgedriver from https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/
150+
// and set the location below:
151+
server_path: '',
152+
cli_args: [
153+
// --verbose
154+
]
155+
}
156+
},
157+
158+
/// ///////////////////////////////////////////////////////////////////////////////
159+
// Configuration for when using cucumber-js (https://cucumber.io) |
160+
// |
161+
// It uses the bundled examples inside the nightwatch examples folder; feel free |
162+
// to adapt this to your own project needs |
163+
/// ///////////////////////////////////////////////////////////////////////////////
164+
'cucumber-js': {
165+
src_folders: ['examples/cucumber-js/features/step_definitions'],
166+
167+
test_runner: {
168+
// set cucumber as the runner
169+
type: 'cucumber',
170+
171+
// define cucumber specific options
172+
options: {
173+
// set the feature path
174+
feature_path: 'node_modules/nightwatch/examples/cucumber-js/*/*.feature'
175+
176+
// start the webdriver session automatically (enabled by default)
177+
// auto_start_session: true
178+
179+
// use parallel execution in Cucumber
180+
// parallel: 2 // set number of workers to use (can also be defined in the cli as --parallel 2
181+
}
182+
}
183+
},
184+
185+
/// ///////////////////////////////////////////////////////////////////////////////
186+
// Configuration for when using the browserstack.com cloud service |
187+
// |
188+
// Please set the username and access key by setting the environment variables: |
189+
// - BROWSERSTACK_USER |
190+
// - BROWSERSTACK_KEY |
191+
// .env files are supported |
192+
/// ///////////////////////////////////////////////////////////////////////////////
193+
browserstack: {
194+
selenium: {
195+
host: 'hub-cloud.browserstack.com',
196+
port: 443
197+
},
198+
// More info on configuring capabilities can be found on:
199+
// https://www.browserstack.com/automate/capabilities?tag=selenium-4
200+
desiredCapabilities: {
201+
'bstack:options': {
202+
userName: `${BROWSERSTACK_USER}`,
203+
accessKey: `${BROWSERSTACK_KEY}`
204+
}
205+
},
206+
207+
disable_error_log: true,
208+
webdriver: {
209+
timeout_options: {
210+
timeout: 15000,
211+
retry_attempts: 3
212+
},
213+
keep_alive: true,
214+
start_process: false
215+
}
216+
},
217+
218+
'browserstack.local': {
219+
extends: 'browserstack',
220+
desiredCapabilities: {
221+
'browserstack.local': true
222+
}
223+
},
224+
225+
'browserstack.chrome': {
226+
extends: 'browserstack',
227+
desiredCapabilities: {
228+
browserName: 'chrome',
229+
chromeOptions: {
230+
w3c: true
231+
}
232+
}
233+
},
234+
235+
'browserstack.firefox': {
236+
extends: 'browserstack',
237+
desiredCapabilities: {
238+
browserName: 'firefox'
239+
}
240+
},
241+
242+
'browserstack.ie': {
243+
extends: 'browserstack',
244+
desiredCapabilities: {
245+
browserName: 'internet explorer',
246+
browserVersion: '11.0'
247+
}
248+
},
249+
250+
'browserstack.safari': {
251+
extends: 'browserstack',
252+
desiredCapabilities: {
253+
browserName: 'safari'
254+
}
255+
},
256+
257+
'browserstack.local_chrome': {
258+
extends: 'browserstack.local',
259+
desiredCapabilities: {
260+
browserName: 'chrome'
261+
}
262+
},
263+
264+
'browserstack.local_firefox': {
265+
extends: 'browserstack.local',
266+
desiredCapabilities: {
267+
browserName: 'firefox'
268+
}
269+
},
270+
/// ///////////////////////////////////////////////////////////////////////////////
271+
// Configuration for when using the Selenium service, either locally or remote, |
272+
// like Selenium Grid |
273+
/// ///////////////////////////////////////////////////////////////////////////////
274+
selenium_server: {
275+
// Selenium Server is running locally and is managed by Nightwatch
276+
selenium: {
277+
start_process: true,
278+
port: 4444,
279+
server_path: (Services.seleniumServer ? Services.seleniumServer.path : ''),
280+
cli_args: {
281+
'webdriver.gecko.driver': (Services.geckodriver ? Services.geckodriver.path : ''),
282+
'webdriver.chrome.driver': (Services.chromedriver ? Services.chromedriver.path : '')
283+
}
284+
}
285+
},
286+
287+
'selenium.chrome': {
288+
extends: 'selenium_server',
289+
desiredCapabilities: {
290+
browserName: 'chrome',
291+
chromeOptions: {
292+
w3c: true
293+
}
294+
}
295+
},
296+
297+
'selenium.firefox': {
298+
extends: 'selenium_server',
299+
desiredCapabilities: {
300+
browserName: 'firefox',
301+
'moz:firefoxOptions': {
302+
args: geckoArgs
303+
}
304+
}
305+
}
306+
}
307+
}
308+
309+
const baseSettings = deepmerge(defaultSettings, webdriverServerSettings())
310+
311+
module.exports = deepmerge(baseSettings, adaptUserSettings(userOptions))
312+
313+
function adaptUserSettings (settings) {
314+
// The path to nightwatch external globals file needs to be made absolute
315+
// if it is supplied in an additional config file, due to merging of config files
316+
if (settings.globals_path) {
317+
settings.globals_path = path.resolve(settings.globals_path)
318+
}
319+
320+
return settings
321+
}
322+
323+
function webdriverServerSettings () {
324+
if (useSelenium) {
325+
return {
326+
selenium: {
327+
start_process: true,
328+
host: '127.0.0.1',
329+
port: 4444,
330+
server_path: require('selenium-server').path,
331+
cli_args: {
332+
'webdriver.chrome.driver': Services.chromedriver.path,
333+
'webdriver.gecko.driver': Services.geckodriver.path
334+
}
335+
}
336+
}
337+
}
338+
339+
return {
340+
webdriver: {
341+
start_process: true,
342+
port: 9515,
343+
server_path: Services.chromedriver.path
344+
}
345+
}
346+
}
347+
348+
function loadServices () {
349+
try {
350+
Services.seleniumServer = require('selenium-server')
351+
} catch (err) {}
352+
353+
try {
354+
Services.chromedriver = require('chromedriver')
355+
} catch (err) {}
356+
357+
try {
358+
Services.geckodriver = require('geckodriver')
359+
} catch (err) {}
360+
}

0 commit comments

Comments
 (0)