Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 75985e4

Browse files
authored
feat: add Nightwatch.js as test framework option (#572)
1 parent 899aa8e commit 75985e4

File tree

10 files changed

+438
-1
lines changed

10 files changed

+438
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ yarn create nuxt-app <my-project>
6565
- [Jest](https://github.com/facebook/jest)
6666
- [AVA](https://github.com/avajs/ava)
6767
- [WebdriverIO](https://webdriver.io)
68+
- [Nightwatch](https://nightwatchjs.org)
6869
1. Rendering mode
6970
- [Universal (SSR / Static)](https://nuxtjs.org/guide/#server-rendered-universal-ssr-)
7071
- [SPA](https://nuxtjs.org/guide/#single-page-applications-spa-)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
// Refer to the online docs for more details: https://nightwatchjs.org/gettingstarted/configuration/
2+
const Services = {}; loadServices()
3+
4+
module.exports = {
5+
// An array of folders (excluding subfolders) where your tests are located;
6+
// if this is not specified, the test source must be passed as the second argument to the test runner.
7+
src_folders: ['test/e2e/specs'],
8+
9+
exclude: [],
10+
11+
// See https://nightwatchjs.org/guide/working-with-page-objects/
12+
page_objects_path: 'test/e2e/pageObjects',
13+
14+
// See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands
15+
custom_commands_path: '',
16+
17+
// See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-assertions
18+
custom_assertions_path: '',
19+
20+
// See https://nightwatchjs.org/guide/#external-globals
21+
globals_path: 'nightwatch_globals.js',
22+
23+
webdriver: {},
24+
25+
test_settings: {
26+
default: {
27+
disable_error_log: false,
28+
launch_url: 'https://nightwatchjs.org',
29+
30+
screenshots: {
31+
enabled: false,
32+
path: 'screens',
33+
on_failure: true
34+
},
35+
36+
desiredCapabilities: {
37+
browserName: 'chrome'
38+
},
39+
40+
webdriver: {
41+
start_process: true,
42+
server_path: 'node_modules/.bin/chromedriver',
43+
port: 9515
44+
}
45+
},
46+
47+
safari: {
48+
desiredCapabilities: {
49+
browserName: 'safari',
50+
alwaysMatch: {
51+
acceptInsecureCerts: false
52+
}
53+
},
54+
webdriver: {
55+
port: 4445,
56+
start_process: true,
57+
server_path: '/usr/bin/safaridriver'
58+
}
59+
},
60+
61+
firefox: {
62+
desiredCapabilities: {
63+
browserName: 'firefox',
64+
alwaysMatch: {
65+
// Enable this if you encounter unexpected SSL certificate errors in Firefox
66+
// acceptInsecureCerts: true,
67+
'moz:firefoxOptions': {
68+
args: [
69+
// '-headless',
70+
// '-verbose'
71+
]
72+
}
73+
}
74+
},
75+
webdriver: {
76+
start_process: true,
77+
// default_path_prefix: '/wd/hub',
78+
use_legacy_jsonwire: true,
79+
port: 4444,
80+
server_path: (Services.geckodriver ? Services.geckodriver.path : ''),
81+
cli_args: [
82+
// very verbose geckodriver logs
83+
// '-vv'
84+
]
85+
}
86+
},
87+
88+
chrome: {
89+
desiredCapabilities: {
90+
browserName: 'chrome',
91+
chromeOptions: {
92+
// This tells Chromedriver to run using the legacy JSONWire protocol (not required in Chrome 78)
93+
// w3c: false,
94+
// More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/
95+
args: [
96+
// '--no-sandbox',
97+
// '--ignore-certificate-errors',
98+
// '--allow-insecure-localhost',
99+
// '--headless'
100+
]
101+
}
102+
},
103+
104+
webdriver: {
105+
start_process: true,
106+
port: 9515,
107+
server_path: (Services.chromedriver ? Services.chromedriver.path : ''),
108+
cli_args: [
109+
// --verbose
110+
]
111+
}
112+
},
113+
114+
// ////////////////////////////////////////////////////////////////////////////////
115+
// Configuration for when using the browserstack.com cloud service |
116+
// |
117+
// Please set the username and access key by setting the environment variables: |
118+
// - BROWSERSTACK_USER |
119+
// - BROWSERSTACK_KEY |
120+
// .env files are supported |
121+
// ////////////////////////////////////////////////////////////////////////////////
122+
browserstack: {
123+
selenium: {
124+
host: 'hub-cloud.browserstack.com',
125+
port: 443
126+
},
127+
// More info on configuring capabilities can be found on:
128+
// https://www.browserstack.com/automate/capabilities?tag=selenium-4
129+
desiredCapabilities: {
130+
'bstack:options': {
131+
local: 'false',
132+
userName: '{BROWSERSTACK_USER}',
133+
accessKey: '{BROWSERSTACK_KEY}'
134+
}
135+
},
136+
137+
disable_error_log: true,
138+
webdriver: {
139+
keep_alive: true,
140+
start_process: false
141+
}
142+
},
143+
144+
'browserstack.chrome': {
145+
extends: 'browserstack',
146+
desiredCapabilities: {
147+
browserName: 'chrome',
148+
chromeOptions: {
149+
// This tells Chromedriver to run using the legacy JSONWire protocol
150+
// More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/
151+
w3c: false
152+
}
153+
}
154+
},
155+
156+
'browserstack.firefox': {
157+
extends: 'browserstack',
158+
desiredCapabilities: {
159+
browserName: 'firefox'
160+
}
161+
},
162+
163+
'browserstack.ie': {
164+
extends: 'browserstack',
165+
desiredCapabilities: {
166+
browserName: 'IE',
167+
browserVersion: '11.0',
168+
'bstack:options': {
169+
os: 'Windows',
170+
osVersion: '10',
171+
local: 'false',
172+
seleniumVersion: '3.5.2',
173+
resolution: '1366x768'
174+
}
175+
}
176+
},
177+
178+
// ////////////////////////////////////////////////////////////////////////////////
179+
// Configuration for when using the Selenium service, either locally or remote, |
180+
// like Selenium Grid |
181+
// ////////////////////////////////////////////////////////////////////////////////
182+
selenium: {
183+
// Selenium Server is running locally and is managed by Nightwatch
184+
selenium: {
185+
start_process: true,
186+
port: 4444,
187+
server_path: (Services.seleniumServer ? Services.seleniumServer.path : ''),
188+
cli_args: {
189+
'webdriver.gecko.driver': (Services.geckodriver ? Services.geckodriver.path : ''),
190+
'webdriver.chrome.driver': (Services.chromedriver ? Services.chromedriver.path : '')
191+
}
192+
}
193+
},
194+
195+
'selenium.chrome': {
196+
extends: 'selenium',
197+
desiredCapabilities: {
198+
browserName: 'chrome',
199+
chromeOptions: {
200+
w3c: false
201+
}
202+
}
203+
},
204+
205+
'selenium.firefox': {
206+
extends: 'selenium',
207+
desiredCapabilities: {
208+
browserName: 'firefox',
209+
'moz:firefoxOptions': {
210+
args: [
211+
// '-headless',
212+
// '-verbose'
213+
]
214+
}
215+
}
216+
}
217+
}
218+
}
219+
220+
function loadServices () {
221+
try {
222+
Services.seleniumServer = require('selenium-server')
223+
} catch (err) {}
224+
225+
try {
226+
Services.chromedriver = require('chromedriver')
227+
} catch (err) {}
228+
229+
try {
230+
Services.geckodriver = require('geckodriver')
231+
} catch (err) {}
232+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// External Globals doc: https://nightwatchjs.org/guide/#external-globals
2+
3+
module.exports = {
4+
// this controls whether to abort the test execution when an assertion failed and skip the rest
5+
// it's being used in waitFor commands and expect assertions
6+
abortOnAssertionFailure: true,
7+
8+
// this will overwrite the default polling interval (currently 500ms) for waitFor commands
9+
// and expect assertions that use retry
10+
waitForConditionPollInterval: 500,
11+
12+
// default timeout value in milliseconds for waitFor commands and implicit waitFor value for
13+
// expect assertions
14+
waitForConditionTimeout: 5000,
15+
16+
// this will cause waitFor commands on elements to throw an error if multiple
17+
// elements are found using the given locate strategy and selector
18+
throwOnMultipleElementsReturned: false,
19+
20+
// controls the timeout value for async hooks. Expects the done() callback to be invoked within this time
21+
// or an error is thrown
22+
asyncHookTimeout: 10000,
23+
24+
// controls the timeout value for when running async unit tests. Expects the done() callback to be invoked within this time
25+
// or an error is thrown
26+
unitTestsTimeout: 2000,
27+
28+
// controls the timeout value for when executing the global async reporter. Expects the done() callback to be invoked within this time
29+
// or an error is thrown
30+
customReporterCallbackTimeout: 20000,
31+
32+
// Automatically retrying failed assertions - You can tell Nightwatch to automatically retry failed assertions until a given timeout is reached, before the test runner gives up and fails the test.
33+
retryAssertionTimeout: 1000
34+
35+
// 'default' : {
36+
// myGlobal : function() {
37+
// return 'I\'m a method';
38+
// }
39+
// },
40+
41+
// 'test_env' : {
42+
// myGlobal: 'test_global',
43+
// beforeEach : function() {
44+
// }
45+
// },
46+
47+
//
48+
// External before hook is ran at the beginning of the tests run, before creating the Selenium session
49+
// before(cb) {
50+
// cb();
51+
// },
52+
53+
//
54+
// External beforeEach hook ran before each test suite is started
55+
// beforeEach(browser, cb) {
56+
// cb();
57+
// },
58+
59+
//
60+
// External after hook is ran at the very end of the tests run, after closing the Selenium session
61+
// after(cb) {
62+
// cb();
63+
// },
64+
65+
//
66+
// External afterEach hook ran after each test suite is finished
67+
// afterEach(browser, cb) {
68+
// browser.perform(function() {
69+
// //console.log('GLOBAL afterEach')
70+
// cb();
71+
// });
72+
// },
73+
74+
//
75+
// The global reporter is invoked before calling the built-in junit reporter (or a custom reporter specified using the --reporter CLI option).
76+
// reporter(results, cb) {
77+
// cb();
78+
// }
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"scripts": {
3+
"test:e2e": "nightwatch"
4+
},
5+
"devDependencies": {
6+
"nightwatch": "^1.3.6",
7+
"chromedriver": "^86.0.0"
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
commands: [],
3+
url: 'http://localhost:3000',
4+
elements: {
5+
docButton: {
6+
selector: '.button--green'
7+
},
8+
githubButton: {
9+
selector: '.button--grey'
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
describe('Example test', () => {
2+
test('open app correctly', (browser) => {
3+
const main = browser.page.main()
4+
main.navigate()
5+
main.assert.visible('@docButton')
6+
main.assert.visible('@githubButton')
7+
browser.end()
8+
})
9+
})

packages/create-nuxt-app/lib/prompts.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ module.exports = [
8181
{ name: 'None', value: 'none' },
8282
{ name: 'Jest', value: 'jest' },
8383
{ name: 'AVA', value: 'ava' },
84-
{ name: 'WebdriverIO', value: 'webdriverio' }
84+
{ name: 'WebdriverIO', value: 'webdriverio' },
85+
{ name: 'Nightwatch', value: 'nightwatch' }
8586
],
8687
default: 'none'
8788
},

0 commit comments

Comments
 (0)