Skip to content

Commit f9a9e27

Browse files
Merge branch 'e2e-po-tests' of https://github.com/zewa666/skeleton-navigation into zewa666-e2e-po-tests
2 parents b02d4e7 + 31866dc commit f9a9e27

7 files changed

+247
-4
lines changed

protractor.conf.js

+17
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@ exports.config = {
88
},
99
onPrepare: function() {
1010
browser.ignoreSynchronization = true;
11+
12+
by.addLocator('valueBind', function (bindingModel, opt_parentElement) {
13+
var using = opt_parentElement || document;
14+
var matches = using.querySelectorAll('*[value\\.bind="' + bindingModel +'"]');
15+
var result = undefined;
16+
17+
if (matches.length === 0) {
18+
result = null;
19+
} else if (matches.length === 1) {
20+
result = matches[0];
21+
} else {
22+
result = matches;
23+
}
24+
25+
return result;
26+
});
27+
1128
},
1229

1330
//seleniumAddress: 'http://0.0.0.0:4444',

test/e2e/dist/demo.spec.js

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,46 @@
11
"use strict";
22

3+
var PageObject_Welcome = require("./welcome.po.js").PageObject_Welcome;
4+
var PageObject_Skeleton = require("./skeleton.po.js").PageObject_Skeleton;
5+
6+
37
describe("aurelia skeleton app", function () {
8+
var po_welcome, po_skeleton;
9+
410
beforeEach(function () {
11+
po_skeleton = new PageObject_Skeleton();
12+
po_welcome = new PageObject_Welcome();
13+
514
browser.get("http://localhost:9000");
615

716
browser.executeAsyncScript("var cb = arguments[arguments.length - 1];" + "document.addEventListener(\"aurelia-composed\", function (e) {" + " cb(\"Aurelia App composed\")" + "}, false);").then(function (result) {
817
console.log(result);
918
});
1019
});
1120

12-
it("should load the page", function () {
13-
expect(browser.getTitle()).toBe("Welcome | Aurelia");
21+
it("should load the page and display the initial page title", function () {
22+
expect(po_skeleton.getCurrentPageTitle()).toBe("Welcome | Aurelia");
23+
});
24+
25+
it("should display greeting", function () {
26+
expect(po_welcome.getGreeting()).toBe("Welcome to the Aurelia Navigation App!");
27+
});
28+
29+
it("should automatically write down the fullname", function () {
30+
po_welcome.setFirstname("Rob");
31+
po_welcome.setLastname("Eisenberg");
32+
expect(po_welcome.getFullname()).toBe("ROB EISENBERG");
33+
});
34+
35+
it("should show alert message when clicking submit button", function () {
36+
expect(po_welcome.openAlertDialog()).toBe(true);
37+
38+
// close it again otherwhise your testing browser starts to hang
39+
/*po_welcome.closeAlert();*/
40+
});
41+
42+
iit("should navigate to flickr page", function () {
43+
po_skeleton.navigateTo("#/flickr");
44+
expect(po_skeleton.getCurrentPageTitle()).toBe("Flickr | Aurelia");
1445
});
1546
});

test/e2e/dist/skeleton.po.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"use strict";
2+
3+
var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); };
4+
5+
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
6+
7+
var PageObject_Skeleton = exports.PageObject_Skeleton = (function () {
8+
function PageObject_Skeleton() {
9+
_classCallCheck(this, PageObject_Skeleton);
10+
}
11+
12+
_prototypeProperties(PageObject_Skeleton, null, {
13+
getCurrentPageTitle: {
14+
value: function getCurrentPageTitle() {
15+
return browser.getTitle();
16+
},
17+
writable: true,
18+
configurable: true
19+
},
20+
navigateTo: {
21+
value: function navigateTo(href) {
22+
var deferred = protractor.promise.defer();
23+
element(by.css("a[href=\"" + href + "\"]")).click().then(function () {
24+
browser.sleep(2000);
25+
deferred.fulfill(true);
26+
});
27+
28+
return deferred.promise;
29+
},
30+
writable: true,
31+
configurable: true
32+
}
33+
});
34+
35+
return PageObject_Skeleton;
36+
})();
37+
exports.__esModule = true;

test/e2e/dist/welcome.po.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"use strict";
2+
3+
var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); };
4+
5+
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
6+
7+
var PageObject_Welcome = exports.PageObject_Welcome = (function () {
8+
function PageObject_Welcome() {
9+
_classCallCheck(this, PageObject_Welcome);
10+
}
11+
12+
_prototypeProperties(PageObject_Welcome, null, {
13+
getGreeting: {
14+
value: function getGreeting() {
15+
return element(by.tagName("h2")).getText();
16+
},
17+
writable: true,
18+
configurable: true
19+
},
20+
setFirstname: {
21+
value: function setFirstname(value) {
22+
return element(by.valueBind("firstName")).clear().sendKeys(value);
23+
},
24+
writable: true,
25+
configurable: true
26+
},
27+
setLastname: {
28+
value: function setLastname(value) {
29+
return element(by.valueBind("lastName")).clear().sendKeys(value);
30+
},
31+
writable: true,
32+
configurable: true
33+
},
34+
getFullname: {
35+
value: function getFullname() {
36+
return element(by.css(".help-block")).getText();
37+
},
38+
writable: true,
39+
configurable: true
40+
},
41+
pressSubmitButton: {
42+
value: function pressSubmitButton() {
43+
return element(by.css("button[type=\"submit\"]")).click();
44+
},
45+
writable: true,
46+
configurable: true
47+
},
48+
openAlertDialog: {
49+
value: function openAlertDialog() {
50+
var _this = this;
51+
return browser.wait(function () {
52+
_this.pressSubmitButton();
53+
54+
return browser.switchTo().alert().then(function (alert) {
55+
alert.dismiss();return true;
56+
}, function () {
57+
return false;
58+
});
59+
});
60+
},
61+
writable: true,
62+
configurable: true
63+
},
64+
closeAlert: {
65+
value: function closeAlert() {},
66+
writable: true,
67+
configurable: true
68+
}
69+
});
70+
71+
return PageObject_Welcome;
72+
})();
73+
exports.__esModule = true;

test/e2e/src/demo.spec.js

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
import {PageObject_Welcome} from './welcome.po.js';
2+
import {PageObject_Skeleton} from './skeleton.po.js';
3+
14
describe('aurelia skeleton app', function() {
5+
var po_welcome,
6+
po_skeleton;
7+
28
beforeEach( () => {
9+
po_skeleton = new PageObject_Skeleton();
10+
po_welcome = new PageObject_Welcome();
11+
312
browser.get('http://localhost:9000');
413

514
browser.executeAsyncScript(
@@ -12,7 +21,26 @@ describe('aurelia skeleton app', function() {
1221
});
1322
});
1423

15-
it('should load the page', function() {
16-
expect(browser.getTitle()).toBe('Welcome | Aurelia');
24+
it('should load the page and display the initial page title', () => {
25+
expect(po_skeleton.getCurrentPageTitle()).toBe('Welcome | Aurelia');
26+
});
27+
28+
it('should display greeting', () => {
29+
expect(po_welcome.getGreeting()).toBe('Welcome to the Aurelia Navigation App!');
30+
});
31+
32+
it('should automatically write down the fullname', () => {
33+
po_welcome.setFirstname('Rob');
34+
po_welcome.setLastname('Eisenberg');
35+
expect(po_welcome.getFullname()).toBe('ROB EISENBERG');
36+
});
37+
38+
it('should show alert message when clicking submit button', () => {
39+
expect(po_welcome.openAlertDialog()).toBe(true);
40+
});
41+
42+
it('should navigate to flickr page', () => {
43+
po_skeleton.navigateTo('#/flickr');
44+
expect(po_skeleton.getCurrentPageTitle()).toBe('Flickr | Aurelia');
1745
});
1846
});

test/e2e/src/skeleton.po.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export class PageObject_Skeleton {
2+
3+
constructor() {
4+
5+
}
6+
7+
getCurrentPageTitle() {
8+
return browser.getTitle();
9+
}
10+
11+
navigateTo(href) {
12+
var deferred = protractor.promise.defer();
13+
element(by.css('a[href="' + href + '"]')).click().then( () => {
14+
browser.sleep(2000);
15+
deferred.fulfill(true);
16+
});
17+
18+
return deferred.promise;
19+
}
20+
}

test/e2e/src/welcome.po.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
export class PageObject_Welcome {
2+
3+
constructor() {
4+
5+
}
6+
7+
getGreeting() {
8+
return element(by.tagName('h2')).getText();
9+
}
10+
11+
setFirstname(value) {
12+
return element(by.valueBind('firstName')).clear().sendKeys(value);
13+
}
14+
15+
setLastname(value) {
16+
return element(by.valueBind('lastName')).clear().sendKeys(value);
17+
}
18+
19+
getFullname() {
20+
return element(by.css('.help-block')).getText();
21+
}
22+
23+
pressSubmitButton() {
24+
return element(by.css('button[type="submit"]')).click();
25+
}
26+
27+
openAlertDialog() {
28+
return browser.wait(() => {
29+
this.pressSubmitButton();
30+
31+
return browser.switchTo().alert().then(
32+
function(alert) { alert.dismiss(); return true; },
33+
function() { return false; }
34+
);
35+
});
36+
}
37+
}

0 commit comments

Comments
 (0)