Skip to content

Commit 307b475

Browse files
Zdravko BranzovZdravko Branzov
Zdravko Branzov
authored and
Zdravko Branzov
committed
chore: add ui tests
1 parent 56b4f31 commit 307b475

30 files changed

+1273
-114
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ demo-vue/platforms/
2525
/src/*.tgz
2626
/publish/package/*.tgz
2727
/publish/package/**/*
28-
/publish/src/**/*
28+
/publish/src/**/*
29+
test-results.xml
30+
**/reports/**/*
31+
**/mochawesome-report/**/*
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
"android23": {
3+
"platformName": "Android",
4+
"platformVersion": "6.0",
5+
"deviceName": "Android",
6+
"lt": 60000,
7+
"appActivity": "com.tns.NativeScriptActivity",
8+
"newCommandTimeout": 720,
9+
"noReset": true,
10+
"fullReset": false,
11+
"app": ""
12+
},
13+
"android24": {
14+
"platformName": "Android",
15+
"platformVersion": "7.0",
16+
"deviceName": "Emulator-Api24-Google",
17+
"avd":"Emulator-Api24-Google",
18+
"lt": 60000,
19+
"newCommandTimeout": 720,
20+
"appium-version": "1.8.1",
21+
"appActivity": "com.tns.NativeScriptActivity",
22+
"noReset": true,
23+
"fullReset": false,
24+
"app": "",
25+
"automationName": "Appium",
26+
"density": 3.2,
27+
"offsetPixels": 51
28+
},
29+
"android24.sauce": {
30+
"platformName": "Android",
31+
"platformVersion": "7.0",
32+
"deviceName": "Android GoogleAPI Emulator",
33+
"lt": 60000,
34+
"newCommandTimeout": 720,
35+
"appiumVersion": "1.9.1",
36+
"noReset": true,
37+
"fullReset": false,
38+
"app": "",
39+
"idleTimeout": 120,
40+
"automationName": "Appium"
41+
},
42+
"android25": {
43+
"platformName": "Android",
44+
"platformVersion": "7.1",
45+
"deviceName": "Google Pixel GoogleAPI",
46+
"lt": 60000,
47+
"appActivity": "com.tns.NativeScriptActivity",
48+
"newCommandTimeout": 720,
49+
"noReset": true,
50+
"fullReset": false,
51+
"app": ""
52+
},
53+
"android27": {
54+
"platformName": "Android",
55+
"platformVersion": "8.1",
56+
"deviceName": "Emulator-Api27-Google",
57+
"lt": 60000,
58+
"appActivity": "com.tns.NativeScriptActivity",
59+
"newCommandTimeout": 720,
60+
"noReset": true,
61+
"fullReset": false,
62+
"app": ""
63+
},
64+
"sim.iPhoneX.iOS112": {
65+
"platformName": "iOS",
66+
"platformVersion": "11.2",
67+
"deviceName": "iPhone X",
68+
"appium-version": "1.8.0",
69+
"density": 3,
70+
"offsetPixels": 87,
71+
"noReset": true,
72+
"fullReset": false,
73+
"app": ""
74+
},
75+
"sim.iPhoneX.iOS113": {
76+
"platformName": "iOS",
77+
"platformVersion": "11.3",
78+
"deviceName": "iPhone X",
79+
"appium-version": "1.8.0",
80+
"density": 3,
81+
"offsetPixels": 87,
82+
"noReset": true,
83+
"fullReset": false,
84+
"app": ""
85+
},
86+
"sim.iPhoneX.ios11": {
87+
"platformName": "iOS",
88+
"platformVersion": "11.2",
89+
"deviceName": "iPhone X",
90+
"appium-version": "1.8.1",
91+
"noReset": true,
92+
"fullReset": false,
93+
"app": "",
94+
"idleTimeout": 120,
95+
"automationName": "Appium"
96+
},
97+
"sim.iPhoneX.ios12": {
98+
"platformName": "iOS",
99+
"platformVersion": "12.1",
100+
"deviceName": "iPhone X",
101+
"appiumVersion": "1.9.1",
102+
"noReset": true,
103+
"fullReset": false,
104+
"density": 3,
105+
"offsetPixels": 87,
106+
"app": "",
107+
"idleTimeout": 120,
108+
"automationName": "Appium"
109+
}
110+
}

demo-angular/e2e/config/mocha.opts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
--timeout 200000
2+
--recursive e2e
3+
--reporter mocha-multi
4+
--reporter-options mochawesome=-,mocha-junit-reporter=test-results.xml
5+
--exit

demo-angular/e2e/helper.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { AppiumDriver, SearchOptions, Direction, UIElement } from "nativescript-dev-appium";
2+
import { runType } from "nativescript-dev-appium/lib/parser";
3+
4+
const isAndroid: boolean = runType.includes("android");
5+
6+
export const QUEUE_WAIT_TIME: number = 600000; // Sometimes SauceLabs threads are not available and the tests wait in a queue to start. Wait 10 min before timeout.
7+
8+
export async function navigateBackToHome(driver: AppiumDriver, view?: string) {
9+
let location = view !== undefined ? view : "PickerField - Angular";
10+
let homeTitle = await driver.findElementByTextIfExists(location, SearchOptions.exact);
11+
while (homeTitle === undefined) {
12+
await driver.navBack();
13+
await driver.wait(1000);
14+
homeTitle = await driver.findElementByTextIfExists(location, SearchOptions.exact);
15+
}
16+
}
17+
18+
export async function navigateBackToView(driver: AppiumDriver, view: string) {
19+
await navigateBackToHome(driver, view);
20+
}
21+
22+
export async function scrollToElement(driver: AppiumDriver, element: string, direction: Direction = Direction.down) {
23+
let listView: UIElement;
24+
if (isAndroid) {
25+
listView = await driver.findElementByClassName("android.widget.FrameLayout");
26+
}
27+
else {
28+
listView = await driver.findElementByClassName("XCUIElementTypeTable");
29+
}
30+
const listItem = await listView.scrollTo(
31+
direction,
32+
() => driver.findElementByText(element, SearchOptions.contains),
33+
600
34+
);
35+
return listItem;
36+
}
37+
38+
export async function scrollToElementInListView(driver: AppiumDriver, element: string, direction: Direction = Direction.down) {
39+
let listView: UIElement;
40+
if (isAndroid) {
41+
listView = await driver.findElementByClassName("android.widget.ListView");
42+
}
43+
else {
44+
listView = await driver.findElementByClassName("XCUIElementTypeTable");
45+
}
46+
const listItem = await listView.scrollTo(
47+
direction,
48+
() => driver.findElementByText(element, SearchOptions.contains),
49+
600
50+
);
51+
return listItem;
52+
}
53+
54+
export async function swipe(driver: AppiumDriver, item: any, direction: Direction) {
55+
const rectangle = await item.getRectangle();
56+
const centerX = rectangle.x + rectangle.width / 2;
57+
const centerY = rectangle.y + rectangle.height / 2;
58+
let swipeX;
59+
if (direction === Direction.right) {
60+
const windowSize = await driver.driver.getWindowSize();
61+
swipeX = windowSize.width - 10;
62+
} else if (direction === Direction.left) {
63+
swipeX = 10;
64+
}
65+
66+
if (isAndroid) {
67+
const wd = driver.wd();
68+
const action = new wd.TouchAction(driver.driver);
69+
action.press({ x: centerX, y: centerY })
70+
.wait(200)
71+
.moveTo({ x: swipeX, y: centerY })
72+
.release();
73+
await action.perform();
74+
}
75+
else {
76+
await driver.driver.execute('mobile: dragFromToForDuration', {
77+
duration: 2.0,
78+
fromX: centerX,
79+
fromY: centerY,
80+
toX: swipeX,
81+
toY: centerY
82+
});
83+
}
84+
}
85+
86+
export async function swipeToElement(driver: AppiumDriver, element: string, direction: Direction = Direction.down) {
87+
let listView;
88+
if (isAndroid) {
89+
listView = await driver.findElementByClassName("android.widget.FrameLayout");
90+
}
91+
else {
92+
listView = await driver.findElementByClassName("XCUIElementTypeCollectionView");
93+
}
94+
95+
let item = await driver.findElementByTextIfExists(element, SearchOptions.exact);
96+
while (item === undefined) {
97+
await listView.swipe(direction);
98+
await driver.wait(500);
99+
item = await driver.findElementByTextIfExists(element, SearchOptions.contains);
100+
}
101+
return item;
102+
}

demo-angular/e2e/setup.ts

Lines changed: 9 additions & 0 deletions
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+
});

demo-angular/e2e/tests.e2e.ts

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import { AppiumDriver, createDriver, SearchOptions, Direction, UIElement } from "nativescript-dev-appium";
2+
import { expect } from "chai";
3+
import { isSauceLab, runType } from "nativescript-dev-appium/lib/parser";
4+
import { navigateBackToHome, scrollToElement, scrollToElementInListView, QUEUE_WAIT_TIME } from "./helper";
5+
const fs = require('fs');
6+
const addContext = require('mochawesome/addContext');
7+
const rimraf = require('rimraf');
8+
9+
const isSauceRun = isSauceLab;
10+
11+
describe("Picker", () => {
12+
let driver: AppiumDriver;
13+
14+
before(async function () {
15+
this.timeout(QUEUE_WAIT_TIME);
16+
driver = await createDriver();
17+
driver.defaultWaitTime = 15000;
18+
let dir = "mochawesome-report";
19+
if (!fs.existsSync(dir)) {
20+
fs.mkdirSync(dir);
21+
}
22+
rimraf('mochawesome-report/*', function () { });
23+
});
24+
25+
after(async () => {
26+
if (isSauceRun) {
27+
driver.sessionId().then(function (sessionId) {
28+
console.log("Report https://saucelabs.com/beta/tests/" + sessionId);
29+
});
30+
}
31+
await driver.quit();
32+
console.log("Quit driver!");
33+
});
34+
35+
afterEach(async function () {
36+
if (this.currentTest.state && this.currentTest.state === "failed") {
37+
let png = await driver.logScreenshot(this.currentTest.title);
38+
fs.copyFile(png, './mochawesome-report/' + this.currentTest.title + '.png', function (err) {
39+
if (err) {
40+
throw err;
41+
}
42+
console.log('Screenshot saved.');
43+
});
44+
addContext(this, './' + this.currentTest.title + '.png');
45+
}
46+
});
47+
48+
const gettingStarted = "Getting Started";
49+
let field: UIElement;
50+
describe(gettingStarted, () => {
51+
it("Navigate to Getting started example", async () => {
52+
const getStarted = await scrollToElement(driver, gettingStarted);
53+
await getStarted.click();
54+
field = await driver.findElementByText("Click here");
55+
expect(field).to.exist;
56+
});
57+
58+
it("Click field and select item", async () => {
59+
await field.click();
60+
const itemText = "Item 38";
61+
const item38 = await scrollToElement(driver, itemText);
62+
await item38.click();
63+
const title = await driver.findElementByText(gettingStarted);
64+
expect(title).to.exist;
65+
const item = await driver.findElementByText(itemText);
66+
expect(item).to.exist;
67+
});
68+
69+
it("Click field and cancel selection", async () => {
70+
let item38 = await driver.findElementByText("Item 38");
71+
await item38.click();
72+
const cancel = await driver.findElementByAccessibilityId("Close");
73+
await cancel.click();
74+
item38 = await driver.findElementByText("Item 38");
75+
expect(item38).to.exist;
76+
});
77+
});
78+
79+
const styling = "Styling"
80+
describe(styling, () => {
81+
it("Navigate to Styling example", async () => {
82+
await navigateBackToHome(driver);
83+
const stylingExample = await scrollToElement(driver, styling);
84+
await stylingExample.click();
85+
field = await driver.findElementByText("This is hint");
86+
expect(field).to.exist;
87+
});
88+
89+
it("Click field and select item", async () => {
90+
await field.click();
91+
const itemText = "Item 6";
92+
const item6 = await scrollToElementInListView(driver, itemText);
93+
await item6.click();
94+
const title = await driver.findElementByText(styling);
95+
expect(title).to.exist;
96+
const item = await driver.findElementByText(itemText);
97+
expect(item).to.exist;
98+
});
99+
});
100+
101+
const valueApis = "Value APIs"
102+
describe(valueApis, () => {
103+
it("Navigate to Value APIs example", async () => {
104+
await navigateBackToHome(driver);
105+
const valueExample = await scrollToElement(driver, valueApis);
106+
await valueExample.click();
107+
field = await driver.findElementByText("Click here");
108+
expect(field).to.exist;
109+
});
110+
111+
it("Click field and select item", async () => {
112+
await field.click();
113+
const itemText = "Item 1";
114+
const item1 = await scrollToElement(driver, itemText);
115+
await item1.click();
116+
const title = await driver.findElementByText(valueApis);
117+
expect(title).to.exist;
118+
const description = await driver.findElementByText("Description 1");
119+
expect(description).to.exist;
120+
});
121+
});
122+
123+
const reactive = "Reactive forms"
124+
describe(reactive, () => {
125+
it("Navigate to Value APIs example", async () => {
126+
await navigateBackToHome(driver);
127+
const reactiveExample = await scrollToElement(driver, reactive);
128+
await reactiveExample.click();
129+
field = await driver.findElementByText("The Godfather");
130+
expect(field).to.exist;
131+
});
132+
133+
it("Click field and select item", async () => {
134+
await field.click();
135+
const itemText = "The Wizard of Oz";
136+
const item1 = await scrollToElementInListView(driver, itemText);
137+
await item1.click();
138+
const title = await driver.findElementByText("Reactive Forms");
139+
expect(title).to.exist;
140+
const pickedItem = await driver.findElementByText(itemText);
141+
expect(pickedItem).to.exist;
142+
});
143+
});
144+
});

0 commit comments

Comments
 (0)