Skip to content

Commit d231f1a

Browse files
committed
Set up acceptance tests with protractor and chromedriver
https://github.com/angular/protractor/blob/master/docs/getting-started.md
1 parent 6c09120 commit d231f1a

File tree

6 files changed

+251
-53
lines changed

6 files changed

+251
-53
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@
33
- Install [node.js](http://nodejs.org/)
44
- mac with [homebrew](http://brew.sh/): `brew install node`
55
- Download and install [node-webkit](https://github.com/rogerwang/node-webkit#downloads)
6+
- Download and install [Chrome Browser](https://www.google.com/intl/en/chrome/browser/)
67
- Install [PhantomJS](http://phantomjs.org/)
78
- mac with homebrew: `brew install phantomjs`
89
- Install [Grunt](http://gruntjs.com/) CLI `npm install -g grunt-cli`
910

11+
## Bootstrapping the project
12+
13+
```bash
14+
npm install
15+
./node_modules/.bin/webdriver-manager update
16+
```
17+
1018
## Development commands
1119

1220
- Run the app:

acceptance/HelloTest.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
describe('Hello World', function() {
2+
3+
describe('when the app starts', function() {
4+
it('says "Hello World"', function() {
5+
browser.get('#');
6+
expect(element(by.css("h1")).getText()).toBe("Hello World!");
7+
});
8+
});
9+
10+
describe('typing a name', function() {
11+
it('says "Hello <name>"', function() {
12+
browser.get('#');
13+
element(by.css("input#name")).clear();
14+
element(by.css("input#name")).sendKeys("Arthur");
15+
expect(element(by.css("h1")).getText()).toBe("Hello Arthur!");
16+
});
17+
});
18+
});

package.json

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,53 @@
11
{
2-
"name": "node-webkit-angular-tdd-sample",
3-
"version": "0.0.0",
4-
"description": "A Mac/Windows/Linux app example written in javascript using node-webkit, angularjs, bootstrap 3, jasmine, karma, and protractor",
5-
"main": "http://localhost:3020/",
6-
"node-main": "main.js",
7-
"window": {
8-
"toolbar": false
9-
},
10-
"scripts": {
11-
"test": "./node_modules/.bin/karma start --single-run",
12-
"start": "open -n -a node-webkit `pwd`"
13-
},
14-
"repository": {
15-
"type": "git",
16-
"url": "git://github.com/avh4-scratch/node-webkit-angular-tdd-sample.git"
17-
},
18-
"keywords": [
19-
"node",
20-
"node-webkit",
21-
"angularjs",
22-
"bootstrap",
23-
"karma",
24-
"jasmine",
25-
"protractor"
26-
],
27-
"author": "Aaron VonderHaar <[email protected]>",
28-
"license": "MIT",
29-
"bugs": {
30-
"url": "https://github.com/avh4-scratch/node-webkit-angular-tdd-sample/issues"
31-
},
32-
"homepage": "https://github.com/avh4-scratch/node-webkit-angular-tdd-sample",
33-
"devDependencies": {
34-
"bower": "~1.2.8",
35-
"karma-script-launcher": "~0.1.0",
36-
"karma-chrome-launcher": "~0.1.2",
37-
"karma-firefox-launcher": "~0.1.3",
38-
"karma-html2js-preprocessor": "~0.1.0",
39-
"karma-jasmine": "~0.1.5",
40-
"requirejs": "~2.1.11",
41-
"karma-requirejs": "~0.2.1",
42-
"karma-coffee-preprocessor": "~0.1.3",
43-
"karma-phantomjs-launcher": "~0.1.2",
44-
"karma": "~0.10.9",
45-
"grunt": "~0.4.3",
46-
"grunt-node-webkit-builder": "~0.1.17"
47-
},
48-
"dependencies": {
49-
"connect": "~2.14.1"
50-
}
2+
"name": "node-webkit-angular-tdd-sample",
3+
"version": "0.0.0",
4+
"description": "A Mac/Windows/Linux app example written in javascript using node-webkit, angularjs, bootstrap 3, jasmine, karma, and protractor",
5+
"main": "http://localhost:3020/",
6+
"node-main": "main.js",
7+
"window": {
8+
"toolbar": false
9+
},
10+
"scripts": {
11+
"test": "./node_modules/.bin/karma start --single-run",
12+
"start": "open -n -a node-webkit `pwd`",
13+
"acceptance-test": "./scripts/acceptance-test.sh"
14+
},
15+
"repository": {
16+
"type": "git",
17+
"url": "git://github.com/avh4-scratch/node-webkit-angular-tdd-sample.git"
18+
},
19+
"keywords": [
20+
"node",
21+
"node-webkit",
22+
"angularjs",
23+
"bootstrap",
24+
"karma",
25+
"jasmine",
26+
"protractor"
27+
],
28+
"author": "Aaron VonderHaar <[email protected]>",
29+
"license": "MIT",
30+
"bugs": {
31+
"url": "https://github.com/avh4-scratch/node-webkit-angular-tdd-sample/issues"
32+
},
33+
"homepage": "https://github.com/avh4-scratch/node-webkit-angular-tdd-sample",
34+
"devDependencies": {
35+
"bower": "~1.2.8",
36+
"karma-script-launcher": "~0.1.0",
37+
"karma-chrome-launcher": "~0.1.2",
38+
"karma-firefox-launcher": "~0.1.3",
39+
"karma-html2js-preprocessor": "~0.1.0",
40+
"karma-jasmine": "~0.1.5",
41+
"requirejs": "~2.1.11",
42+
"karma-requirejs": "~0.2.1",
43+
"karma-coffee-preprocessor": "~0.1.3",
44+
"karma-phantomjs-launcher": "~0.1.2",
45+
"karma": "~0.10.9",
46+
"grunt": "~0.4.3",
47+
"grunt-node-webkit-builder": "~0.1.17",
48+
"protractor": "~0.20.1"
49+
},
50+
"dependencies": {
51+
"connect": "~2.14.1"
52+
}
5153
}

protractor.js

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
// A reference configuration file.
2+
exports.config = {
3+
// ----- How to setup Selenium -----
4+
//
5+
// There are three ways to specify how to use Selenium. Specify one of the
6+
// following:
7+
//
8+
// 1. seleniumServerJar - to start Selenium Standalone locally.
9+
// 2. seleniumAddress - to connect to a Selenium server which is already
10+
// running.
11+
// 3. sauceUser/sauceKey - to use remote Selenium servers via SauceLabs.
12+
//
13+
// If the chromeOnly option is specified, no Selenium server will be started,
14+
// and chromeDriver will be used directly (from the location specified in
15+
// chromeDriver)
16+
17+
// The location of the selenium standalone server .jar file, relative
18+
// to the location of this config. If no other method of starting selenium
19+
// is found, this will default to
20+
// node_modules/protractor/selenium/selenium-server...
21+
seleniumServerJar: null,
22+
// The port to start the selenium server on, or null if the server should
23+
// find its own unused port.
24+
seleniumPort: null,
25+
// Chromedriver location is used to help the selenium standalone server
26+
// find chromedriver. This will be passed to the selenium jar as
27+
// the system property webdriver.chrome.driver. If null, selenium will
28+
// attempt to find chromedriver using PATH.
29+
chromeDriver: './node_modules/protractor/selenium/chromedriver',
30+
// If true, only chromedriver will be started, not a standalone selenium.
31+
// Tests for browsers other than chrome will not run.
32+
chromeOnly: false,
33+
// Additional command line options to pass to selenium. For example,
34+
// if you need to change the browser timeout, use
35+
// seleniumArgs: ['-browserTimeout=60'],
36+
seleniumArgs: [],
37+
38+
// If sauceUser and sauceKey are specified, seleniumServerJar will be ignored.
39+
// The tests will be run remotely using SauceLabs.
40+
sauceUser: null,
41+
sauceKey: null,
42+
43+
// The address of a running selenium server. If specified, Protractor will
44+
// connect to an already running instance of selenium. This usually looks like
45+
// seleniumAddress: 'http://localhost:4444/wd/hub'
46+
seleniumAddress: null,
47+
48+
// The timeout for each script run on the browser. This should be longer
49+
// than the maximum time your application needs to stabilize between tasks.
50+
allScriptsTimeout: 11000,
51+
52+
// ----- What tests to run -----
53+
//
54+
// Spec patterns are relative to the location of this config.
55+
specs: [
56+
'acceptance/*.js',
57+
],
58+
59+
// Patterns to exclude.
60+
exclude: [],
61+
62+
// ----- Capabilities to be passed to the webdriver instance ----
63+
//
64+
// For a full list of available capabilities, see
65+
// https://code.google.com/p/selenium/wiki/DesiredCapabilities
66+
// and
67+
// https://code.google.com/p/selenium/source/browse/javascript/webdriver/capabilities.js
68+
capabilities: {
69+
'browserName': 'chrome'
70+
},
71+
72+
// If you would like to run more than one instance of webdriver on the same
73+
// tests, use multiCapabilities, which takes an array of capabilities.
74+
// If this is specified, capabilities will be ignored.
75+
multiCapabilities: [],
76+
77+
// ----- More information for your tests ----
78+
//
79+
// A base URL for your application under test. Calls to protractor.get()
80+
// with relative paths will be prepended with this.
81+
baseUrl: 'http://localhost:3020/',
82+
83+
// Selector for the element housing the angular app - this defaults to
84+
// body, but is necessary if ng-app is on a descendant of <body>
85+
rootElement: 'body',
86+
87+
// A callback function called once protractor is ready and available, and
88+
// before the specs are executed
89+
// You can specify a file containing code to run by setting onPrepare to
90+
// the filename string.
91+
onPrepare: function() {
92+
// At this point, global 'protractor' object will be set up, and jasmine
93+
// will be available. For example, you can add a Jasmine reporter with:
94+
// jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter(
95+
// 'outputdir/', true, true));
96+
},
97+
98+
// The params object will be passed directly to the protractor instance,
99+
// and can be accessed from your test. It is an arbitrary object and can
100+
// contain anything you may need in your test.
101+
// This can be changed via the command line as:
102+
// --params.login.user 'Joe'
103+
params: {
104+
login: {
105+
user: 'Jane',
106+
password: '1234'
107+
}
108+
},
109+
110+
// ----- The test framework -----
111+
//
112+
// Jasmine and Cucumber are fully supported as a test and assertion framework.
113+
// Mocha has limited beta support. You will need to include your own
114+
// assertion framework if working with mocha.
115+
framework: 'jasmine',
116+
117+
// ----- Options to be passed to minijasminenode -----
118+
//
119+
// See the full list at https://github.com/juliemr/minijasminenode
120+
jasmineNodeOpts: {
121+
// onComplete will be called just before the driver quits.
122+
onComplete: null,
123+
// If true, display spec names.
124+
isVerbose: false,
125+
// If true, print colors to the terminal.
126+
showColors: true,
127+
// If true, include stack traces in failures.
128+
includeStackTrace: true,
129+
// Default time to wait in ms before a test fails.
130+
defaultTimeoutInterval: 30000
131+
},
132+
133+
// ----- Options to be passed to mocha -----
134+
//
135+
// See the full list at http://visionmedia.github.io/mocha/
136+
mochaOpts: {
137+
ui: 'bdd',
138+
reporter: 'list'
139+
},
140+
141+
// ----- Options to be passed to cucumber -----
142+
cucumberOpts: {
143+
// Require files before executing the features.
144+
require: 'cucumber/stepDefinitions.js',
145+
// Only execute the features or scenarios with tags matching @dev.
146+
// This may be an array of strings to specify multiple tags to include.
147+
tags: '@dev',
148+
// How to format features (default: progress)
149+
format: 'summary'
150+
},
151+
152+
// ----- The cleanup step -----
153+
//
154+
// A callback function called once the tests have finished running and
155+
// the webdriver instance has been shut down. It is passed the exit code
156+
// (0 if the tests passed or 1 if not).
157+
onCleanUp: function() {}
158+
};

public/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css"/>
77
<script src="bower_components/jquery/dist/jquery.min.js"></script>
88
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
9-
<script src="bower_components/angular/angular.min.js"></script>
10-
<script src="js/HelloController.js"></script>
119
</head>
12-
<body>
13-
<div ng-app="HelloApp" class="container">
10+
<body ng-app="HelloApp">
11+
<div class="container">
1412
<div class="jumbotron" ng-controller="HelloController">
1513
<h1>Hello<span ng-if="name"> </span>{{ name }}!</h1>
1614
<p>We are using node.js <script>document.write(process.version)</script>.</p>
@@ -19,5 +17,7 @@ <h1>Hello<span ng-if="name"> </span>{{ name }}!</h1>
1917
<input class="form-control" id="name" ng-model="name"/>
2018
</div>
2119
</div>
20+
<script src="bower_components/angular/angular.min.js"></script>
21+
<script src="js/HelloController.js"></script>
2222
</body>
2323
</html>

scripts/acceptance-test.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
echo "=> Starting node.js"
4+
node main.js &
5+
PID=$!
6+
7+
echo "=> Running acceptance tests with protractor"
8+
./node_modules/.bin/protractor protractor.js
9+
STATUS="$?"
10+
11+
kill "$PID"
12+
exit "$STATUS"

0 commit comments

Comments
 (0)