Skip to content

Commit b065d01

Browse files
authored
QACOE-226: Added README file & setup code for quick run (#10)
* Added ReadMe updated ReadMe, config, tests/ * added hyperlinks in ReadME added hyperlinks in ReadME * fix hyperlinks
1 parent 27b4902 commit b065d01

File tree

6 files changed

+284
-289
lines changed

6 files changed

+284
-289
lines changed

nightwatchJS/README.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
2+
<br />
3+
4+
# NightwatchJS
5+
<!-- CONTENTS -->
6+
## Contents
7+
8+
- [Intro](/nightwatchJS/#Intro)
9+
- [Installation](/nightwatchJS/#Installation)
10+
- [Write Tests](/nightwatchJS/#Write-Tests)
11+
- [How to Run](/nightwatchJS/#How-to-Run)
12+
13+
<br/>
14+
15+
<!-- Intro -->
16+
## Intro
17+
This project is to automate Ecosia web application using NightwatchJS framework.
18+
19+
NightwatchJS is E2E testing solution for web applications
20+
21+
<!-- Installation -->
22+
## Installation
23+
24+
1. Install NodeJS on your machine, go to [NodeJS](https://nodejs.org/en/) for respective platform downloads
25+
2. Install npm , (Node Package Manager) from [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) this is a package manager helps in installing required dependencies with apt versions. For beginners this is just like Maven in Java projects.
26+
3. `npm init --y`
27+
this command will create `package.json` file with default values. You can update project name, version, scripts, licenses.
28+
4. ` npm install nightwatch`
29+
this command will install nightwatch dependency with latest stable version available.
30+
5. `npm install chromedriver`
31+
this command will install chromedriver dependency and no more configuration needed unlike old way of setting browser path & references.
32+
6. Current test automation frameworks run based on configuration starting from test runner, browser capabilities, environments, features/specs/steps/pages references, reporting etc. Similarly Nightwatch also used `nightwatch.conf.js` configuration file. Add a file with same name and copy paste below code.
33+
```
34+
module.exports = {
35+
"src_folders" : ["tests"],
36+
37+
"webdriver" : {
38+
"start_process": true,
39+
"server_path": "node_modules/.bin/chromedriver",
40+
"port": 9515
41+
},
42+
43+
"test_settings" : {
44+
"default" : {
45+
"desiredCapabilities": {
46+
"browserName": "chrome"
47+
}
48+
}
49+
}
50+
}
51+
```
52+
7. Refer to docs (https://nightwatchjs.org/guide/configuration/settings.html) for complete settings default values.
53+
8. Global file usage, you can define `globals.js` an external file instead of having them in nightwatch config file.
54+
you can setup hooks like before, after, beforeEach, afterEach which are mostly re-usable for multiple specs
55+
copy the below code as its defaults
56+
```
57+
module.exports = {
58+
'default' : {
59+
isLocal : true,
60+
},
61+
62+
'integration' : {
63+
isLocal : false
64+
},
65+
66+
// External before hook is ran at the beginning of the tests run, before creating the Selenium session
67+
before: function(done) {
68+
// run this only for the local-env
69+
if (this.isLocal) {
70+
// start the local server
71+
App.startServer(function() {
72+
// server listening
73+
done();
74+
});
75+
} else {
76+
done();
77+
}
78+
},
79+
80+
// External after hook is ran at the very end of the tests run, after closing the Selenium session
81+
after: function(done) {
82+
// run this only for the local-env
83+
if (this.isLocal) {
84+
// start the local server
85+
App.stopServer(function() {
86+
// shutting down
87+
done();
88+
});
89+
} else {
90+
done();
91+
}
92+
},
93+
94+
// This will be run before each test suite is started
95+
beforeEach: function(browser, done) {
96+
// getting the session info
97+
browser.status(function(result) {
98+
console.log(result.value);
99+
done();
100+
});
101+
},
102+
103+
// This will be run after each test suite is finished
104+
afterEach: function(browser, done) {
105+
console.log(browser.currentTest);
106+
done();
107+
}
108+
};
109+
```
110+
9. Reporting
111+
112+
<!-- Write Tests -->
113+
## Write Tests
114+
115+
1. Create a separate folder for tests in your project, e.g.: tests. Each file inside it will be loaded as a test suite by the Nightwatch test runner.
116+
2. Here's a basic test suite example which opens the search engine Ecosia.org, searches for the term "nightwatch", then verifies if the term first result is the Nightwatch.js website.
117+
```
118+
module.exports = {
119+
'Demo test ecosia.org' : function(browser) {
120+
browser
121+
.url('https://www.ecosia.org/')
122+
.waitForElementVisible('body')
123+
.assert.titleContains('Ecosia')
124+
.assert.visible('input[type=search]')
125+
.setValue('input[type=search]', 'nightwatch')
126+
.assert.visible('button[type=submit]')
127+
.click('button[type=submit]')
128+
.assert.containsText('.mainline-results', 'Nightwatch.js')
129+
.end();
130+
}
131+
};
132+
```
133+
3. BDD example
134+
...
135+
136+
137+
<!-- How to Run -->
138+
## How to Run
139+
1. npx nightwatch [source] [options] - in this source is the test file location and options are different capabilities to run
140+
for our tests run the following command
141+
`npx nightwatch tests/Demo.js`
142+
It invokes chrome browser with single test
143+
144+
OR
145+
146+
2. Add "tests/" to the source folder in config file in this way ` "src_folders" : ["tests/"],`
147+
3. Add nightwatch to the test script in package.json in this way
148+
```
149+
"scripts": {
150+
"test": "nightwatch"
151+
},
152+
```
153+
4. Now run `npm test`
154+
this command will trigger all tests and its subfolder tests via Chrome browser
155+
156+
157+
158+

nightwatchJS/globals.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
module.exports = {
2+
'default' : {
3+
isLocal : true,
4+
},
5+
6+
'integration' : {
7+
isLocal : false
8+
},
9+
10+
// External before hook is ran at the beginning of the tests run, before creating the Selenium session
11+
before: function(done) {
12+
// run this only for the local-env
13+
if (this.isLocal) {
14+
// start the local server
15+
App.startServer(function() {
16+
// server listening
17+
done();
18+
});
19+
} else {
20+
done();
21+
}
22+
},
23+
24+
// External after hook is ran at the very end of the tests run, after closing the Selenium session
25+
after: function(done) {
26+
// run this only for the local-env
27+
if (this.isLocal) {
28+
// start the local server
29+
App.stopServer(function() {
30+
// shutting down
31+
done();
32+
});
33+
} else {
34+
done();
35+
}
36+
},
37+
38+
// This will be run before each test suite is started
39+
beforeEach: function(browser, done) {
40+
// getting the session info
41+
browser.status(function(result) {
42+
console.log(result.value);
43+
done();
44+
});
45+
},
46+
47+
// This will be run after each test suite is finished
48+
afterEach: function(browser, done) {
49+
console.log(browser.currentTest);
50+
done();
51+
}
52+
};

0 commit comments

Comments
 (0)