Skip to content

Commit 0ced1ec

Browse files
committed
e2e tests using protractor
1 parent 8341ee8 commit 0ced1ec

File tree

6 files changed

+99
-1
lines changed

6 files changed

+99
-1
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ Based on the awesome [unit testing example](https://github.com/roblouie/unit-tes
55

66
Clone repo, run `npm install`.
77

8+
Unit Tests
9+
----------
10+
811
To run the tests, run `npm test`.
912

1013
See the example test in `src/app/app.component.spec.ts` for an example of a component test.
14+
15+
End-To-End Tests (Browser-Only)
16+
-------------------------------
17+
18+
To serve the app, run `ionic serve`.
19+
20+
To run the end-to-end tests, run (while the app is being served) `npm run e2e`.
21+
22+
See the example end-to-end test in `e2e/app.e2e-spec.ts`.

e2e/app.e2e-spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Page } from './app.po';
2+
3+
describe('App', function() {
4+
let page: Page;
5+
6+
beforeEach(() => {
7+
page = new Page();
8+
});
9+
10+
describe('default screen', () => {
11+
beforeEach(() => {
12+
page.navigateTo('/');
13+
});
14+
15+
it('should have a title saying Page One', () => {
16+
page.getTitle().then(title => {
17+
expect(title).toEqual('Page One');
18+
});
19+
});
20+
})
21+
});

e2e/app.po.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { browser } from 'protractor';
2+
3+
export class Page {
4+
5+
navigateTo(destination) {
6+
return browser.get(destination);
7+
}
8+
9+
getTitle() {
10+
return browser.getTitle();
11+
}
12+
13+
}

e2e/tsconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compileOnSave": false,
3+
"compilerOptions": {
4+
"declaration": false,
5+
"emitDecoratorMetadata": true,
6+
"experimentalDecorators": true,
7+
"module": "commonjs",
8+
"moduleResolution": "node",
9+
"outDir": "../dist/out-tsc-e2e",
10+
"sourceMap": true,
11+
"target": "es5",
12+
"typeRoots": [
13+
"../node_modules/@types"
14+
]
15+
}
16+
}

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"build": "ionic-app-scripts build",
99
"ionic:build": "ionic-app-scripts build",
1010
"ionic:serve": "ionic-app-scripts serve",
11-
"test": "karma start ./test-config/karma.conf.js"
11+
"test": "karma start ./test-config/karma.conf.js",
12+
"e2e": "webdriver-manager update --standalone false --gecko false; protractor ./test-config/protractor.conf.js"
1213
},
1314
"dependencies": {
1415
"@angular/common": "2.4.8",
@@ -39,14 +40,17 @@
3940
"angular2-template-loader": "^0.6.2",
4041
"html-loader": "^0.4.5",
4142
"jasmine": "^2.5.3",
43+
"jasmine-spec-reporter": "^3.2.0",
4244
"karma": "^1.5.0",
4345
"karma-chrome-launcher": "^2.0.0",
4446
"karma-jasmine": "^1.1.0",
4547
"karma-jasmine-html-reporter": "^0.2.2",
4648
"karma-sourcemap-loader": "^0.3.7",
4749
"karma-webpack": "^2.0.3",
4850
"null-loader": "^0.1.1",
51+
"protractor": "^5.1.1",
4952
"ts-loader": "^2.0.3",
53+
"ts-node": "^3.0.2",
5054
"typescript": "2.1.6"
5155
},
5256
"version": "0.0.1",

test-config/protractor.conf.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Protractor configuration file, see link for more information
2+
// https://github.com/angular/protractor/blob/master/lib/config.ts
3+
4+
/*global jasmine */
5+
var SpecReporter = require('jasmine-spec-reporter').SpecReporter;
6+
7+
exports.config = {
8+
allScriptsTimeout: 11000,
9+
specs: [
10+
'../e2e/**/*.e2e-spec.ts'
11+
],
12+
capabilities: {
13+
'browserName': 'chrome'
14+
},
15+
directConnect: true,
16+
baseUrl: 'http://localhost:8100/',
17+
framework: 'jasmine',
18+
jasmineNodeOpts: {
19+
showColors: true,
20+
defaultTimeoutInterval: 30000,
21+
print: function() {}
22+
},
23+
useAllAngular2AppRoots: true,
24+
beforeLaunch: function() {
25+
require('ts-node').register({
26+
project: 'e2e'
27+
});
28+
},
29+
onPrepare: function() {
30+
jasmine.getEnv().addReporter(new SpecReporter());
31+
}
32+
};

0 commit comments

Comments
 (0)