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

Commit 9a1497f

Browse files
feat: add WebdriverIO as test framework option (#528)
* add WebdriverIO as test framework option * fix linter * update snapshot * update snapshot * add wdio packages to renovate.json Co-authored-by: christian-bromann <[email protected]>
1 parent 2b26088 commit 9a1497f

File tree

11 files changed

+409
-5
lines changed

11 files changed

+409
-5
lines changed

.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"@nuxtjs"
44
],
55
"globals": {
6-
"use": true
6+
"use": true,
7+
"browser": true
78
},
89
"rules": {
910
"no-console": "off"

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ yarn create nuxt-app <my-project>
7474
- None
7575
- [Jest](https://github.com/facebook/jest)
7676
- [AVA](https://github.com/avajs/ava)
77+
- [WebdriverIO](https://webdriver.io)
7778
1. Choose rendering mode
7879
- [Universal (SSR / Static)](https://nuxtjs.org/guide/#server-rendered-universal-ssr-)
7980
- [SPA](https://nuxtjs.org/guide/#single-page-applications-spa-)

packages/cna-template/template/_.eslintrc.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,19 @@ module.exports = {
2020
'prettier/vue',
2121
'plugin:prettier/recommended',
2222
<%_ } _%>
23+
<%_ if (test === 'webdriverio') { _%>
24+
'plugin:wdio/recommended',
25+
<%_ } _%>
2326
'plugin:nuxt/recommended'
2427
],
25-
<%_ if (prettier) { _%>
2628
plugins: [
27-
'prettier'
29+
<%_ if (prettier) {_%>
30+
'prettier',
31+
<%_ } _%>
32+
<%_ if (test === 'webdriverio') { _%>
33+
'wdio'
34+
<%_ } _%>
2835
],
29-
<%_ } _%>
3036
// add your custom rules here
3137
rules: {}
3238
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"scripts": {
3+
"test:e2e": "wdio wdio.conf.js"
4+
},
5+
"devDependencies": {
6+
"@wdio/cli": "^6.1.5",
7+
"@wdio/local-runner": "^6.1.6",
8+
"@wdio/mocha-framework": "^6.1.6",
9+
"@wdio/spec-reporter": "^6.1.5",
10+
"@wdio/sync": "^6.1.5",
11+
"eslint-plugin-wdio": "^6.0.12",
12+
"webdriverio": "^6.1.5"
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Page {
2+
open (path = '/') {
3+
browser.url(path)
4+
}
5+
}
6+
7+
module.exports = new Page()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const Page = require('../pageObjects/main.page')
2+
3+
describe('Example test', () => {
4+
it('should open correct app', () => {
5+
Page.open()
6+
expect(browser).toHaveTitle('Example')
7+
})
8+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
exports.config = {
2+
//
3+
// ====================
4+
// Runner Configuration
5+
// ====================
6+
//
7+
// ==================
8+
// Specify Test Files
9+
// ==================
10+
// Define which test specs should run. The pattern is relative to the directory
11+
// from which `wdio` was called. Notice that, if you are calling `wdio` from an
12+
// NPM script (see https://docs.npmjs.com/cli/run-script) then the current working
13+
// directory is where your package.json resides, so `wdio` will be called from there.
14+
//
15+
specs: [
16+
'./test/e2e/**/*.spec.js'
17+
],
18+
// Patterns to exclude.
19+
exclude: [
20+
// 'path/to/excluded/files'
21+
],
22+
//
23+
// ============
24+
// Capabilities
25+
// ============
26+
// Define your capabilities here. WebdriverIO can run multiple capabilities at the same
27+
// time. Depending on the number of capabilities, WebdriverIO launches several test
28+
// sessions. Within your capabilities you can overwrite the spec and exclude options in
29+
// order to group specific specs to a specific capability.
30+
//
31+
// First, you can define how many instances should be started at the same time. Let's
32+
// say you have 3 different capabilities (Chrome, Firefox, and Safari) and you have
33+
// set maxInstances to 1; wdio will spawn 3 processes. Therefore, if you have 10 spec
34+
// files and you set maxInstances to 10, all spec files will get tested at the same time
35+
// and 30 processes will get spawned. The property handles how many capabilities
36+
// from the same test should run tests.
37+
//
38+
maxInstances: 10,
39+
//
40+
// If you have trouble getting all important capabilities together, check out the
41+
// Sauce Labs platform configurator - a great tool to configure your capabilities:
42+
// https://docs.saucelabs.com/reference/platforms-configurator
43+
//
44+
capabilities: [{
45+
// maxInstances can get overwritten per capability. So if you have an in-house Selenium
46+
// grid with only 5 firefox instances available you can make sure that not more than
47+
// 5 instances get started at a time.
48+
maxInstances: 5,
49+
//
50+
browserName: 'chrome'
51+
// If outputDir is provided WebdriverIO can capture driver session logs
52+
// it is possible to configure which logTypes to include/exclude.
53+
// excludeDriverLogs: ['*'], // pass '*' to exclude all driver session logs
54+
// excludeDriverLogs: ['bugreport', 'server'],
55+
}],
56+
//
57+
// ===================
58+
// Test Configurations
59+
// ===================
60+
// Define all options that are relevant for the WebdriverIO instance here
61+
//
62+
// Level of logging verbosity: trace | debug | info | warn | error | silent
63+
logLevel: 'info',
64+
//
65+
// Set specific log levels per logger
66+
// loggers:
67+
// - webdriver, webdriverio
68+
// - @wdio/applitools-service, @wdio/browserstack-service, @wdio/devtools-service, @wdio/sauce-service
69+
// - @wdio/mocha-framework, @wdio/jasmine-framework
70+
// - @wdio/local-runner, @wdio/lambda-runner
71+
// - @wdio/sumologic-reporter
72+
// - @wdio/cli, @wdio/config, @wdio/sync, @wdio/utils
73+
// Level of logging verbosity: trace | debug | info | warn | error | silent
74+
// logLevels: {
75+
// webdriver: 'info',
76+
// '@wdio/applitools-service': 'info'
77+
// },
78+
//
79+
// If you only want to run your tests until a specific amount of tests have failed use
80+
// bail (default is 0 - don't bail, run all tests).
81+
bail: 0,
82+
//
83+
// Set a base URL in order to shorten url command calls. If your `url` parameter starts
84+
// with `/`, the base url gets prepended, not including the path portion of your baseUrl.
85+
// If your `url` parameter starts without a scheme or `/` (like `some/path`), the base url
86+
// gets prepended directly.
87+
baseUrl: 'http://localhost:3000',
88+
//
89+
// Default timeout for all waitFor* commands.
90+
waitforTimeout: 10000,
91+
//
92+
// Default timeout in milliseconds for request
93+
// if browser driver or grid doesn't send response
94+
connectionRetryTimeout: 120000,
95+
//
96+
// Default request retries count
97+
connectionRetryCount: 3,
98+
//
99+
// Test runner services
100+
// Services take over a specific job you don't want to take care of. They enhance
101+
// your test setup with almost no effort. Unlike plugins, they don't add new
102+
// commands. Instead, they hook themselves up into the test process.
103+
// services: [],
104+
//
105+
// Framework you want to run your specs with.
106+
// The following are supported: Mocha, Jasmine, and Cucumber
107+
// see also: https://webdriver.io/docs/frameworks.html
108+
//
109+
// Make sure you have the wdio adapter package for the specific framework installed
110+
// before running any tests.
111+
framework: 'mocha',
112+
//
113+
// The number of times to retry the entire specfile when it fails as a whole
114+
// specFileRetries: 1,
115+
//
116+
// Whether or not retried specfiles should be retried immediately or deferred to the end of the queue
117+
// specFileRetriesDeferred: false,
118+
//
119+
// Test reporter for stdout.
120+
// The only one supported by default is 'dot'
121+
// see also: https://webdriver.io/docs/dot-reporter.html
122+
reporters: ['spec'],
123+
124+
//
125+
// Options to be passed to Mocha.
126+
// See the full list at http://mochajs.org/
127+
mochaOpts: {
128+
ui: 'bdd',
129+
timeout: 60000
130+
}
131+
//
132+
// =====
133+
// Hooks
134+
// =====
135+
// WebdriverIO provides several hooks you can use to interfere with the test process in order to enhance
136+
// it and to build services around it. You can either apply a single function or an array of
137+
// methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got
138+
// resolved to continue.
139+
/**
140+
* Gets executed once before all workers get launched.
141+
* @param {Object} config wdio configuration object
142+
* @param {Array.<Object>} capabilities list of capabilities details
143+
*/
144+
// onPrepare: function (config, capabilities) {
145+
// },
146+
/**
147+
* Gets executed before a worker process is spawned and can be used to initialise specific service
148+
* for that worker as well as modify runtime environments in an async fashion.
149+
* @param {String} cid capability id (e.g 0-0)
150+
* @param {[type]} caps object containing capabilities for session that will be spawn in the worker
151+
* @param {[type]} specs specs to be run in the worker process
152+
* @param {[type]} args object that will be merged with the main configuration once worker is initialised
153+
* @param {[type]} execArgv list of string arguments passed to the worker process
154+
*/
155+
// onWorkerStart: function (cid, caps, specs, args, execArgv) {
156+
// },
157+
/**
158+
* Gets executed just before initialising the webdriver session and test framework. It allows you
159+
* to manipulate configurations depending on the capability or spec.
160+
* @param {Object} config wdio configuration object
161+
* @param {Array.<Object>} capabilities list of capabilities details
162+
* @param {Array.<String>} specs List of spec file paths that are to be run
163+
*/
164+
// beforeSession: function (config, capabilities, specs) {
165+
// },
166+
/**
167+
* Gets executed before test execution begins. At this point you can access to all global
168+
* variables like `browser`. It is the perfect place to define custom commands.
169+
* @param {Array.<Object>} capabilities list of capabilities details
170+
* @param {Array.<String>} specs List of spec file paths that are to be run
171+
*/
172+
// before: function (capabilities, specs) {
173+
// },
174+
/**
175+
* Runs before a WebdriverIO command gets executed.
176+
* @param {String} commandName hook command name
177+
* @param {Array} args arguments that command would receive
178+
*/
179+
// beforeCommand: function (commandName, args) {
180+
// },
181+
/**
182+
* Hook that gets executed before the suite starts
183+
* @param {Object} suite suite details
184+
*/
185+
// beforeSuite: function (suite) {
186+
// },
187+
/**
188+
* Function to be executed before a test (in Mocha/Jasmine) starts.
189+
*/
190+
// beforeTest: function (test, context) {
191+
// },
192+
/**
193+
* Hook that gets executed _before_ a hook within the suite starts (e.g. runs before calling
194+
* beforeEach in Mocha)
195+
*/
196+
// beforeHook: function (test, context) {
197+
// },
198+
/**
199+
* Hook that gets executed _after_ a hook within the suite starts (e.g. runs after calling
200+
* afterEach in Mocha)
201+
*/
202+
// afterHook: function (test, context, { error, result, duration, passed, retries }) {
203+
// },
204+
/**
205+
* Function to be executed after a test (in Mocha/Jasmine).
206+
*/
207+
// afterTest: function(test, context, { error, result, duration, passed, retries }) {
208+
// },
209+
210+
/**
211+
* Hook that gets executed after the suite has ended
212+
* @param {Object} suite suite details
213+
*/
214+
// afterSuite: function (suite) {
215+
// },
216+
/**
217+
* Runs after a WebdriverIO command gets executed
218+
* @param {String} commandName hook command name
219+
* @param {Array} args arguments that command would receive
220+
* @param {Number} result 0 - command success, 1 - command error
221+
* @param {Object} error error object if any
222+
*/
223+
// afterCommand: function (commandName, args, result, error) {
224+
// },
225+
/**
226+
* Gets executed after all tests are done. You still have access to all global variables from
227+
* the test.
228+
* @param {Number} result 0 - test pass, 1 - test fail
229+
* @param {Array.<Object>} capabilities list of capabilities details
230+
* @param {Array.<String>} specs List of spec file paths that ran
231+
*/
232+
// after: function (result, capabilities, specs) {
233+
// },
234+
/**
235+
* Gets executed right after terminating the webdriver session.
236+
* @param {Object} config wdio configuration object
237+
* @param {Array.<Object>} capabilities list of capabilities details
238+
* @param {Array.<String>} specs List of spec file paths that ran
239+
*/
240+
// afterSession: function (config, capabilities, specs) {
241+
// },
242+
/**
243+
* Gets executed after all workers got shut down and the process is about to exit. An error
244+
* thrown in the onComplete hook will result in the test run failing.
245+
* @param {Object} exitCode 0 - success, 1 - fail
246+
* @param {Object} config wdio configuration object
247+
* @param {Array.<Object>} capabilities list of capabilities details
248+
* @param {<Object>} results object containing test results
249+
*/
250+
// onComplete: function(exitCode, config, capabilities, results) {
251+
// },
252+
/**
253+
* Gets executed when a refresh happens.
254+
* @param {String} oldSessionId session ID of the old session
255+
* @param {String} newSessionId session ID of the new session
256+
*/
257+
// onReload: function(oldSessionId, newSessionId) {
258+
// }
259+
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ module.exports = [
8787
choices: [
8888
{ name: 'None', value: 'none' },
8989
{ name: 'Jest', value: 'jest' },
90-
{ name: 'AVA', value: 'ava' }
90+
{ name: 'AVA', value: 'ava' },
91+
{ name: 'WebdriverIO', value: 'webdriverio' }
9192
],
9293
default: 'none'
9394
},

0 commit comments

Comments
 (0)