Skip to content
This repository was archived by the owner on Aug 28, 2019. It is now read-only.

Commit 86c70a8

Browse files
author
Vasil Chimev
authored
refactor: template-hello-world-ng test to use page object pattern (#1)
* chore: bump angular to 5.2 * refactor(tests): expose HomePage and DetailsPage * chore: update template-hello-world-ng to latest * refactor: template-hello-world-ng test to use page object pattern * chore: update template-hello-world-ng capabilities * chore: update template-hello-world-ng iPhone X image * refactor(e2e): update template-hello-world-ng test * refactor(e2e): update template-hello-world-ng test
1 parent 4d433ca commit 86c70a8

File tree

22 files changed

+368
-170
lines changed

22 files changed

+368
-170
lines changed

template-hello-world-ng/.gitignore

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
.DS_Store
2+
3+
hooks
14
node_modules
25
platforms
3-
*-results.xml
4-
e2e/reports
5-
node_modules
6-
*.tgz
7-
**/**/*.js
6+
87
*.js
9-
**/**/*.map
10-
report.html
11-
instruments*
8+
*.map
9+
10+
e2e/reports
11+
12+
package-lock.json
13+

template-hello-world-ng/.vscode/launch.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,39 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7-
87
{
98
"type": "node",
109
"request": "launch",
1110
"name": "iOS110",
1211
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
1312
"args": [
13+
"${workspaceRoot}/e2e",
1414
"-u",
1515
"tdd",
1616
"--timeout",
1717
"999999",
1818
"--colors",
1919
"--runType",
20-
"sim.iPhoneX",
21-
"${workspaceRoot}/e2e",
20+
"sim.iPhoneX.iOS110",
2221
"--reuseDevice"
2322
],
2423
"internalConsoleOptions": "openOnSessionStart"
2524
},
2625
{
2726
"type": "node",
2827
"request": "launch",
29-
"name": "android24",
28+
"name": "android23",
3029
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
3130
"args": [
31+
"${workspaceRoot}/e2e",
3232
"-u",
3333
"tdd",
3434
"--timeout",
3535
"999999",
36-
"--colors",
36+
"--colors",
3737
"--runType",
38-
"android24",
39-
"${workspaceRoot}/e2e"
38+
"android23",
39+
"--reuseDevice"
4040
],
4141
"internalConsoleOptions": "openOnSessionStart"
4242
}

template-hello-world-ng/app/app.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ In many cases you may want to use the NativeScript core theme instead
99
of writing your own CSS rules. For a full list of class names in the theme
1010
refer to http://docs.nativescript.org/ui/theme.
1111
*/
12-
@import 'nativescript-theme-core/css/core.light.css';
12+
13+
@import '~nativescript-theme-core/css/core.light.css';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* A dynamically generated module when compiled with AoT.
3+
*/
4+
export const AppModuleNgFactory: any;

template-hello-world-ng/app/item/item.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// this import should be first in order to load some required settings (like globals and reflect-metadata)
22
import { platformNativeScript } from "nativescript-angular/platform-static";
33

4+
// "./app.module.ngfactory" is a dynamically generated module when compiled with AoT.
45
import { AppModuleNgFactory } from "./app.module.ngfactory";
56

67
platformNativeScript().bootstrapModuleFactory(AppModuleNgFactory);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// There is a bug in angular: https://github.com/angular/angular-cli/pull/8589/files
2+
// Legendary stuff, its webpack plugin pretty much doesn't work with empty TypeScript files in v1.8.3
3+
void 0;

template-hello-world-ng/app/vendor.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// Snapshot the ~/app.css and the theme
2+
const application = require("application");
3+
require("ui/styling/style-scope");
4+
const appCssContext = require.context("~/", false, /^\.\/app\.(css|scss|less|sass)$/);
5+
global.registerWebpackModules(appCssContext);
6+
application.loadAppCss();
7+
18
require("./vendor-platform");
29

310
require("reflect-metadata");

template-hello-world-ng/e2e/config/appium.capabilities.json

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"lt": 60000,
88
"appActivity": "com.tns.NativeScriptActivity",
99
"newCommandTimeout": 720,
10-
"noReset": false,
11-
"fullReset": true,
10+
"noReset": true,
11+
"fullReset": false,
1212
"app": ""
1313
},
1414
"android21": {
@@ -19,8 +19,8 @@
1919
"lt": 60000,
2020
"appActivity": "com.tns.NativeScriptActivity",
2121
"newCommandTimeout": 720,
22-
"noReset": false,
23-
"fullReset": true,
22+
"noReset": true,
23+
"fullReset": false,
2424
"app": ""
2525
},
2626
"android23": {
@@ -31,8 +31,8 @@
3131
"lt": 60000,
3232
"appActivity": "com.tns.NativeScriptActivity",
3333
"newCommandTimeout": 720,
34-
"noReset": false,
35-
"fullReset": true,
34+
"noReset": true,
35+
"fullReset": false,
3636
"app": ""
3737
},
3838
"android24": {
@@ -62,17 +62,31 @@
6262
"android26": {
6363
"platformName": "Android",
6464
"platformVersion": "8.0",
65-
"deviceName": "Emulator_Api26_Google",
66-
"avd": "Emulator_Api26_Google",
65+
"deviceName": "Emulator-Api26-Google",
66+
"avd": "Emulator-Api26-Google",
67+
"lt": 60000,
68+
"appActivity": "com.tns.NativeScriptActivity",
69+
"newCommandTimeout": 720,
70+
"noReset": true,
71+
"fullReset": false,
72+
"app": ""
73+
},
74+
"android27": {
75+
"platformName": "Android",
76+
"platformVersion": "8.1",
77+
"deviceName": "Emulator-Api27-Google",
78+
"avd": "Emulator-Api27-Google",
6779
"lt": 60000,
6880
"appActivity": "com.tns.NativeScriptActivity",
6981
"newCommandTimeout": 720,
82+
"noReset": true,
83+
"fullReset": false,
7084
"app": ""
7185
},
72-
"sim.iPhone7.iOS100": {
86+
"sim.iPhone7.iOS110": {
7387
"platformName": "iOS",
74-
"platformVersion": "10.0",
75-
"deviceName": "iPhone 7 100",
88+
"platformVersion": "11.2",
89+
"deviceName": "iPhone 7 110",
7690
"noReset": true,
7791
"fullReset": false,
7892
"app": ""
@@ -85,12 +99,20 @@
8599
"fullReset": false,
86100
"app": ""
87101
},
88-
"sim.iPhoneX": {
102+
"sim.iPhoneX.iOS110": {
89103
"platformName": "iOS",
90104
"platformVersion": "11.0",
91105
"deviceName": "iPhone X",
92106
"noReset": true,
93107
"fullReset": false,
94108
"app": ""
109+
},
110+
"sim.iPhoneX.iOS112": {
111+
"platformName": "iOS",
112+
"platformVersion": "11.2",
113+
"deviceName": "iPhone X",
114+
"noReset": true,
115+
"fullReset": false,
116+
"app": ""
95117
}
96-
}
118+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { AppiumDriver } from "nativescript-dev-appium";
2+
import { ImageOptions } from "nativescript-dev-appium/lib/image-options";
3+
import { Players } from "./players";
4+
import { assert } from "chai";
5+
6+
const title = "Details";
7+
8+
export class Details {
9+
10+
constructor(private _driver: AppiumDriver) { }
11+
12+
loaded = async () => {
13+
const lblTitle = await this._driver.findElementByText(title);
14+
assert.isTrue(await lblTitle.isDisplayed());
15+
console.log(title + " loaded!");
16+
}
17+
18+
assertPlayerIsDisplayed = async (playerName: Players) => {
19+
const player = await this._driver.findElementByText(playerName);
20+
assert.isTrue(await player.isDisplayed(), `${playerName} is NOT displayed!`);
21+
}
22+
23+
assertPlayerScreen = async (playerName: Players) => {
24+
const imageName = playerName.toLowerCase() + "PlayerDetails";
25+
const areDetailsCorrect = await this._driver.compareScreen(imageName, 3, 10, ImageOptions.pixel);
26+
assert.isTrue(areDetailsCorrect, `Image does NOT match! Please, refer to ${imageName} image.`);
27+
}
28+
}

template-hello-world-ng/e2e/home.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { AppiumDriver, Direction, SearchOptions } from "nativescript-dev-appium";
2+
import { Players } from "./players";
3+
import { assert } from "chai";
4+
5+
const title = "My App";
6+
7+
export class Home {
8+
9+
constructor(private _driver: AppiumDriver) { }
10+
11+
get players() {
12+
return this._driver.findElementByClassName(this._driver.locators.listView);
13+
}
14+
15+
loaded = async () => {
16+
const lblTitle = await this._driver.findElementByText(title);
17+
assert.isTrue(await lblTitle.isDisplayed());
18+
console.log(title + " loaded!");
19+
}
20+
21+
findPlayer = async (playerName: Players, scrollDirection: Direction = Direction.down, searchOptions: SearchOptions = SearchOptions.contains) => {
22+
const player = await (await this.players).scrollTo(
23+
scrollDirection,
24+
() => this._driver.findElementByText(playerName, searchOptions));
25+
return player;
26+
}
27+
28+
tapOnPlayer = async (playerName: Players) => {
29+
const player = await this.findPlayer(playerName);
30+
await player.tap();
31+
}
32+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export enum Players {
2+
umtiti = "Umtiti",
3+
mathieu = "Mathieu",
4+
masip = "Masip"
5+
}
Binary file not shown.

template-hello-world-ng/e2e/sample-test.e2e.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { AppiumDriver, createDriver, SearchOptions, Direction } from "nativescript-dev-appium";
2+
import { assert } from "chai";
3+
import { Home } from "./home";
4+
import { Details } from "./details";
5+
import { Players } from "./players";
6+
7+
describe("template-hello-world-ng scenario", () => {
8+
let driver: AppiumDriver,
9+
details: Details,
10+
home: Home;
11+
12+
before(async () => {
13+
driver = await createDriver();
14+
details = new Details(driver);
15+
home = new Home(driver);
16+
});
17+
18+
afterEach(async function () {
19+
if (this.currentTest.state === "failed") {
20+
await driver.logPageSource(this.currentTest.title);
21+
await driver.logScreenshot(this.currentTest.title);
22+
}
23+
await driver.navBack();
24+
});
25+
26+
after(async () => {
27+
await driver.quit();
28+
});
29+
30+
it("should swipe to the last player and verify his details", async () => {
31+
await home.loaded();
32+
await home.tapOnPlayer(Players.masip);
33+
34+
await details.loaded();
35+
await details.assertPlayerIsDisplayed(Players.masip);
36+
await details.assertPlayerScreen(Players.masip);
37+
});
38+
});

0 commit comments

Comments
 (0)