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

Commit eeb84a9

Browse files
vchimevvchimev
vchimev
authored and
vchimev
committed
test(TypeScriptApp): add tests
1 parent 5a42e32 commit eeb84a9

File tree

17 files changed

+316
-33
lines changed

17 files changed

+316
-33
lines changed

Diff for: demo/.gitignore

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
webpack.config.js
2-
1+
node_modules
32
platforms
3+
hooks
44
report
55

6+
**/*.map
7+
8+
reports/
9+
test-results.xml
10+
11+
tsconfig.aot.json
12+
613
vendor.js
714
vendor-platform.android.js
815
vendor-platform.ios.js
@@ -11,4 +18,4 @@ vendor.ts
1118
vendor-platform.android.ts
1219
vendor-platform.ios.ts
1320

14-
tsconfig.aot.json
21+
webpack.config.js

Diff for: demo/AngularApp/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
}
2121
},
2222
"exclude": [
23+
"e2e",
2324
"node_modules",
2425
"platforms",
2526
"**/*.aot.ts"

Diff for: demo/JavaScriptApp/package.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@
55
"repository": "<fill-your-repository-here>",
66
"nativescript": {
77
"id": "org.nativescript.JavaScriptApp",
8-
"tns-android": {
9-
"version": "3.4.0-2017-11-13-2"
10-
},
118
"tns-ios": {
12-
"version": "3.4.0-2017-11-9-1"
9+
"version": "next"
10+
},
11+
"tns-android": {
12+
"version": "next"
1313
}
1414
},
1515
"dependencies": {
1616
"nativescript-theme-core": "~1.0.2",
17-
"tns-core-modules": "file:../../../NativeScript/tns-core-modules",
18-
"tns-core-modules-widgets": "^3.4.0-2017-11-2-1"
17+
"tns-core-modules": "next"
1918
},
2019
"devDependencies": {
2120
"babel-traverse": "6.26.0",

Diff for: demo/TypeScriptApp/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
app/**/*.js
2+
e2e/**/*.js
3+

Diff for: demo/TypeScriptApp/.vscode/launch.json

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Android",
11+
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
12+
"args": [
13+
"-u",
14+
"tdd",
15+
"--timeout",
16+
"999999",
17+
"--colors",
18+
"--opts",
19+
"./e2e/config/mocha.opts",
20+
"--runType",
21+
"android23",
22+
"--reuseDevice"
23+
// "${workspaceFolder}/test"
24+
],
25+
"internalConsoleOptions": "openOnSessionStart"
26+
},
27+
{
28+
"type": "node",
29+
"request": "launch",
30+
"name": "IOS",
31+
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
32+
"args": [
33+
"-u",
34+
"tdd",
35+
"--timeout",
36+
"999999",
37+
"--colors",
38+
"--opts",
39+
"./e2e/config/mocha.opts",
40+
"--runType",
41+
"sim.iPhoneX.iOS111",
42+
"--reuseDevice"
43+
// "${workspaceFolder}/test"
44+
],
45+
"internalConsoleOptions": "openOnSessionStart"
46+
},
47+
{
48+
"type": "node",
49+
"request": "launch",
50+
"name": "Launch Program",
51+
"program": "${file}"
52+
}
53+
]
54+
}

Diff for: demo/TypeScriptApp/app/main-page.android.xml

+11-9
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ https://docs.nativescript.org/ui/components.
1010
http://docs.nativescript.org/ui/action-bar
1111
-->
1212
<Page.actionBar>
13-
<ActionBar title="My App" icon="">
14-
</ActionBar>
13+
<ActionBar title="My App" icon=""></ActionBar>
1514
</Page.actionBar>
1615
<!--
1716
The StackLayout stacks UI components on the screen—either vertically or horizontally.
@@ -25,15 +24,18 @@ https://docs.nativescript.org/ui/components.
2524
class names available for styling your app at https://docs.nativescript.org/ui/theme.
2625
-->
2726
<StackLayout class="p-20">
28-
<StackLayout horizontalAlignment="left" verticalAlignment="top" orientation="horizontal">
29-
<GridLayout width="30px" height="30px" backgroundColor="#7F9" margin="10px" />
30-
<GridLayout width="30px" height="30px" class="app-class" margin="10px" />
31-
<GridLayout width="30px" height="30px" class="page-class" margin="10px" />
32-
</StackLayout>
27+
<GridLayout rows="auto, auto, auto" columns="auto, auto">
28+
<GridLayout row="0" automationText="styleInline" width="30px" height="30px" backgroundColor="#7F9" margin="10px" />
29+
<Label row="0" col="1" text="inline style" verticalAlignment="center" />
30+
<GridLayout row="1" automationText="stylePage" width="30px" height="30px" class="page-class" margin="10px" />
31+
<Label row="1" col="1" text="page style" verticalAlignment="center" />
32+
<GridLayout row="2" automationText="styleApp" width="30px" height="30px" class="app-class" margin="10px" />
33+
<Label row="2" col="1" text="app style" verticalAlignment="center" />
34+
</GridLayout>
3335
<Label text="Tap the button" class="h1 text-center"/>
3436
<Button text="TAP" tap="{{ onTap }}" class="btn btn-primary btn-active"/>
3537
<Label text="{{ message }}" class="h2 text-center" textWrap="true"/>
36-
<Button text="Android, Navigate to second-page.xml" tap="goToSecondPage" />
38+
<Button automationText="btnNav" text="Android, Navigate to second-page.xml" tap="goToSecondPage" />
3739
<Label id="platform" text="-" />
3840
</StackLayout>
39-
</Page>
41+
</Page>

Diff for: demo/TypeScriptApp/app/main-page.ios.xml

+11-9
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ https://docs.nativescript.org/ui/components.
1010
http://docs.nativescript.org/ui/action-bar
1111
-->
1212
<Page.actionBar>
13-
<ActionBar title="My App" icon="">
14-
</ActionBar>
13+
<ActionBar title="My App" icon=""></ActionBar>
1514
</Page.actionBar>
1615
<!--
1716
The StackLayout stacks UI components on the screen—either vertically or horizontally.
@@ -25,15 +24,18 @@ https://docs.nativescript.org/ui/components.
2524
class names available for styling your app at https://docs.nativescript.org/ui/theme.
2625
-->
2726
<StackLayout class="p-20">
28-
<StackLayout horizontalAlignment="left" verticalAlignment="top" orientation="horizontal">
29-
<GridLayout width="30px" height="30px" backgroundColor="#999" margin="10px" />
30-
<GridLayout width="30px" height="30px" class="app-class" margin="10px" />
31-
<GridLayout width="30px" height="30px" class="page-class" margin="10px" />
32-
</StackLayout>
27+
<GridLayout rows="auto, auto, auto" columns="auto, auto">
28+
<GridLayout row="0" automationText="styleInline" width="30px" height="30px" backgroundColor="#999" margin="10px" />
29+
<Label row="0" col="1" text="inline style" verticalAlignment="center" />
30+
<GridLayout row="1" automationText="stylePage" width="30px" height="30px" class="page-class" margin="10px" />
31+
<Label row="1" col="1" text="page style" verticalAlignment="center" />
32+
<GridLayout row="2" automationText="styleApp" width="30px" height="30px" class="app-class" margin="10px" />
33+
<Label row="2" col="1" text="app style" verticalAlignment="center" />
34+
</GridLayout>
3335
<Label text="Tap the button" class="h1 text-center"/>
3436
<Button text="TAP" tap="{{ onTap }}" class="btn btn-primary btn-active"/>
3537
<Label text="{{ message }}" class="h2 text-center" textWrap="true"/>
36-
<Button text="iOS, Navigate to second-page.xml" tap="goToSecondPage" />
38+
<Button automationText="btnNav" text="iOS, Navigate to second-page.xml" tap="goToSecondPage" />
3739
<Label id="platform" text="-" />
3840
</StackLayout>
39-
</Page>
41+
</Page>

Diff for: demo/TypeScriptApp/app/views/second-page.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
</ActionBar>
55
</Page.actionBar>
66
<GridLayout>
7-
<Button text="0" width="110" height="110" tap="secondPageTap" />
7+
<Button automationText="btn" text="0" width="110" height="110" tap="secondPageTap" />
88
</GridLayout>
99
</Page>
+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"android19": {
3+
"platformName": "Android",
4+
"platformVersion": "4.4",
5+
"deviceName": "Emulator-Api19-Default",
6+
"avd": "Emulator-Api19-Default",
7+
"lt": 60000,
8+
"appActivity": "com.tns.NativeScriptActivity",
9+
"newCommandTimeout": 720,
10+
"noReset": true,
11+
"fullReset": false,
12+
"app": ""
13+
},
14+
"android21": {
15+
"platformName": "Android",
16+
"platformVersion": "5.0",
17+
"deviceName": "Emulator-Api21-Default",
18+
"avd": "Emulator-Api21-Default",
19+
"lt": 60000,
20+
"appActivity": "com.tns.NativeScriptActivity",
21+
"newCommandTimeout": 720,
22+
"noReset": true,
23+
"fullReset": false,
24+
"app": ""
25+
},
26+
"android23": {
27+
"platformName": "Android",
28+
"platformVersion": "6.0",
29+
"deviceName": "Emulator-Api23-Default",
30+
"avd": "Emulator-Api23-Default",
31+
"lt": 60000,
32+
"appActivity": "com.tns.NativeScriptActivity",
33+
"newCommandTimeout": 720,
34+
"noReset": true,
35+
"fullReset": false,
36+
"app": ""
37+
},
38+
"android24": {
39+
"platformName": "Android",
40+
"platformVersion": "7.0",
41+
"deviceName": "Emulator-Api24-Default",
42+
"avd": "Emulator-Api24-Default",
43+
"lt": 60000,
44+
"appActivity": "com.tns.NativeScriptActivity",
45+
"newCommandTimeout": 720,
46+
"noReset": true,
47+
"fullReset": false,
48+
"app": ""
49+
},
50+
"android25": {
51+
"platformName": "Android",
52+
"platformVersion": "7.1",
53+
"deviceName": "Emulator-Api25-Google",
54+
"avd": "Emulator-Api25-Google",
55+
"lt": 60000,
56+
"appActivity": "com.tns.NativeScriptActivity",
57+
"newCommandTimeout": 720,
58+
"noReset": true,
59+
"fullReset": false,
60+
"app": ""
61+
},
62+
"android26": {
63+
"platformName": "Android",
64+
"platformVersion": "8.0",
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+
"sim.iPhone7.iOS100": {
75+
"platformName": "iOS",
76+
"platformVersion": "10.0",
77+
"deviceName": "iPhone 7 100",
78+
"noReset": true,
79+
"fullReset": false,
80+
"app": ""
81+
},
82+
"sim.iPhone8.iOS110": {
83+
"platformName": "iOS",
84+
"platformVersion": "11.0",
85+
"deviceName": "iPhone 8 110",
86+
"noReset": true,
87+
"fullReset": false,
88+
"app": ""
89+
},
90+
"sim.iPhoneX.iOS110": {
91+
"platformName": "iOS",
92+
"platformVersion": "11.0",
93+
"deviceName": "iPhone X",
94+
"noReset": true,
95+
"fullReset": false,
96+
"app": ""
97+
},
98+
"sim.iPhoneX.iOS111": {
99+
"platformName": "iOS",
100+
"platformVersion": "11.1",
101+
"deviceName": "iPhone X",
102+
"noReset": true,
103+
"fullReset": false,
104+
"app": ""
105+
}
106+
}

Diff for: demo/TypeScriptApp/e2e/config/mocha.opts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--timeout 80000
2+
--recursive e2e
3+
--reporter mocha-multi
4+
--reporter-options spec=-,mocha-junit-reporter=test-results.xml
Loading
Loading

Diff for: demo/TypeScriptApp/e2e/setup.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { startServer, stopServer } from "nativescript-dev-appium";
2+
3+
before("start server", async () => {
4+
await startServer();
5+
});
6+
7+
after("stop server", async () => {
8+
await stopServer();
9+
});

Diff for: demo/TypeScriptApp/e2e/tests.e2e-spec.ts

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { AppiumDriver, createDriver, SearchOptions } from "nativescript-dev-appium";
2+
import { assert } from "chai";
3+
4+
describe("sample scenario", () => {
5+
const defaultWaitTime = 5000;
6+
let driver: AppiumDriver;
7+
8+
before(async () => {
9+
driver = await createDriver();
10+
});
11+
12+
beforeEach(async function () {
13+
try {
14+
const lblPlatform = await getPlatformLabel();
15+
} catch (err) {
16+
console.log("Navigating to main page ...");
17+
await driver.navBack();
18+
}
19+
});
20+
21+
afterEach(async function () {
22+
if (this.currentTest.state === "failed") {
23+
await driver.logScreenshot(this.currentTest.title);
24+
}
25+
});
26+
27+
after(async () => {
28+
await driver.quit();
29+
console.log("Quit driver!");
30+
});
31+
32+
it("should the button on second page work", async () => {
33+
const btnNav = await driver.findElementByText("btnNav");
34+
await btnNav.tap();
35+
36+
const secondPage = await driver.findElementByText("Second Page");
37+
const btn = await driver.findElementByText("btn");
38+
39+
const result = await driver.compareElement(btn, getButtonImageName());
40+
assert.isTrue(result);
41+
42+
await btn.tap();
43+
assert.equal(await btn.text(), 1);
44+
45+
await driver.navBack();
46+
});
47+
48+
it("should the button on main page work", async () => {
49+
const btnTap = await driver.findElementByText("TAP");
50+
await btnTap.tap();
51+
52+
const lblTaps = await driver.findElementByText("taps left", SearchOptions.contains);
53+
const lblTapsText = await lblTaps.text();
54+
assert.isTrue(lblTapsText.includes("41"));
55+
});
56+
57+
const styleTypes = {
58+
"inline": "styleInline",
59+
"page": "stylePage",
60+
"app": "styleApp"
61+
};
62+
63+
for (let styleType in styleTypes) {
64+
it(`should find an element with ${styleType} style applied`, async function () {
65+
const element = await driver.findElementByText(styleTypes[styleType]);
66+
const result = await driver.compareElement(element, getPlatformImageName());
67+
assert.isTrue(result);
68+
});
69+
}
70+
71+
const getButtonImageName = () => { return driver.isAndroid ? "btnAndroid" : "btnIOS"; }
72+
const getPlatformImageName = () => { return driver.isAndroid ? "styleAndroid" : "styleIOS"; }
73+
const getPlatformLabel = async () => { return driver.isAndroid ? await driver.findElementByText("android") : await driver.findElementByText("ios"); }
74+
});

0 commit comments

Comments
 (0)