Skip to content

Commit 212ba99

Browse files
committed
add nightwatch tests
1 parent 8a17b58 commit 212ba99

File tree

10 files changed

+1229
-73
lines changed

10 files changed

+1229
-73
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.DS_Store
22
node_modules
33
/dist
4+
logs/
5+
tests/e2e/reports/
46

57

68
# local env files

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"serve": "vue-cli-service serve",
77
"build": "vue-cli-service build",
88
"test:unit": "vue-cli-service test:unit",
9+
"test:e2e": "vue-cli-service test:e2e",
910
"lint": "vue-cli-service lint"
1011
},
1112
"dependencies": {
@@ -16,17 +17,20 @@
1617
"vuex": "^4.0.0-0"
1718
},
1819
"devDependencies": {
20+
"@babel/eslint-parser": "^7.21.0",
1921
"@vue/cli-plugin-babel": "~5.0.8",
22+
"@vue/cli-plugin-e2e-nightwatch": "~5.0.0",
2023
"@vue/cli-plugin-eslint": "~5.0.8",
2124
"@vue/cli-plugin-router": "~5.0.8",
2225
"@vue/cli-plugin-unit-jest": "~5.0.8",
2326
"@vue/cli-plugin-vuex": "~5.0.8",
2427
"@vue/cli-service": "~5.0.8",
2528
"@vue/compiler-sfc": "^3.0.0",
2629
"@vue/test-utils": "^2.0.0-0",
27-
"@babel/eslint-parser": "^7.21.0",
30+
"chromedriver": "112",
2831
"eslint": "^8.38.0",
2932
"eslint-plugin-vue": "^9.11.0",
33+
"geckodriver": "^3.0.1",
3034
"typescript": "~5.0.4",
3135
"vue-jest": "^5.0.0-0",
3236
"vue3-jest": "^27.0.0-alpha.1"

src/App.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
<button @click="increment">Click</button>
33
<div v-if="count % 2 === 0">Count: {{ count }}. Count is even.</div>
44
<div v-if="count % 2 !== 0">Count: {{ count }}. Count is odd.</div>
5-
6-
<div>PostID: {{ postId }}</div>
5+
<div id="pid">PostID: {{ postId }}</div>
76
</template>
87

98
<script>

tests/e2e/.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
rules: {
3+
'no-unused-expressions': 'off'
4+
}
5+
}

tests/e2e/custom-assertions/nop.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.assertion = {}

tests/e2e/custom-commands/nop.js

Whitespace-only changes.

tests/e2e/globals.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
///////////////////////////////////////////////////////////////////////////////////
2+
// Refer to the entire list of global config settings here:
3+
// https://github.com/nightwatchjs/nightwatch/blob/master/lib/settings/defaults.js#L16
4+
//
5+
// More info on test globals:
6+
// https://nightwatchjs.org/gettingstarted/configuration/#test-globals
7+
//
8+
///////////////////////////////////////////////////////////////////////////////////
9+
10+
module.exports = {
11+
// this controls whether to abort the test execution when an assertion failed and skip the rest
12+
// it's being used in waitFor commands and expect assertions
13+
abortOnAssertionFailure: true,
14+
15+
// this will overwrite the default polling interval (currently 500ms) for waitFor commands
16+
// and expect assertions that use retry
17+
waitForConditionPollInterval: 500,
18+
19+
// default timeout value in milliseconds for waitFor commands and implicit waitFor value for
20+
// expect assertions
21+
waitForConditionTimeout: 5000,
22+
23+
'default': {
24+
/*
25+
The globals defined here are available everywhere in any test env
26+
*/
27+
28+
/*
29+
myGlobal: function() {
30+
return 'I\'m a method';
31+
}
32+
*/
33+
},
34+
35+
'firefox': {
36+
/*
37+
The globals defined here are available only when the chrome testing env is being used
38+
i.e. when running with --env firefox
39+
*/
40+
/*
41+
* myGlobal: function() {
42+
* return 'Firefox specific global';
43+
* }
44+
*/
45+
},
46+
47+
/////////////////////////////////////////////////////////////////
48+
// Global hooks
49+
// - simple functions which are executed as part of the test run
50+
// - take a callback argument which can be called when an async
51+
// async operation is finished
52+
/////////////////////////////////////////////////////////////////
53+
/**
54+
* executed before the test run has started, so before a session is created
55+
*/
56+
/*
57+
before(cb) {
58+
//console.log('global before')
59+
cb();
60+
},
61+
*/
62+
63+
/**
64+
* executed before every test suite has started
65+
*/
66+
/*
67+
beforeEach(browser, cb) {
68+
//console.log('global beforeEach')
69+
cb();
70+
},
71+
*/
72+
73+
/**
74+
* executed after every test suite has ended
75+
*/
76+
/*
77+
afterEach(browser, cb) {
78+
browser.perform(function() {
79+
//console.log('global afterEach')
80+
cb();
81+
});
82+
},
83+
*/
84+
85+
/**
86+
* executed after the test run has finished
87+
*/
88+
/*
89+
after(cb) {
90+
//console.log('global after')
91+
cb();
92+
},
93+
*/
94+
95+
/////////////////////////////////////////////////////////////////
96+
// Global reporter
97+
// - define your own custom reporter
98+
/////////////////////////////////////////////////////////////////
99+
/*
100+
reporter(results, cb) {
101+
cb();
102+
}
103+
*/
104+
}

tests/e2e/page-objects/nop.js

Whitespace-only changes.

tests/e2e/specs/test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// For authoring Nightwatch tests, see
2+
// https://nightwatchjs.org/guide
3+
4+
function testForm(browser) {
5+
browser
6+
.waitForElementVisible('#app')
7+
.expect.element('#app > div').text.to.equal('Count: 0. Count is even.')
8+
9+
browser
10+
.useXpath()
11+
.click("//button[text()='Click']")
12+
.useCss()
13+
.expect.element('#app > div').text.to.equal('Count: 1. Count is odd.')
14+
15+
browser
16+
.useXpath()
17+
.click("//button[text()='Click']")
18+
.useCss()
19+
.expect.element('#app > div').text.to.equal('Count: 2. Count is even.')
20+
}
21+
22+
module.exports = {
23+
'default form interactivity': browser => {
24+
browser.init()
25+
26+
testForm(browser);
27+
28+
browser.expect.element('#pid').text.to.equal('PostID:')
29+
30+
},
31+
32+
'post abc interactivity': browser => {
33+
browser
34+
.init()
35+
.url("http://localhost:8080/abc")
36+
37+
testForm(browser);
38+
39+
browser.useCss().expect.element('#pid').text.to.equal('PostID: abc')
40+
},
41+
}

0 commit comments

Comments
 (0)