Skip to content

Commit 13c5dfb

Browse files
committedSep 5, 2017
test(e2e): cover dynamic ActionBar[Extension] scenarios
1 parent e34cbb7 commit 13c5dfb

File tree

3 files changed

+195
-0
lines changed

3 files changed

+195
-0
lines changed
 
+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
import {
2+
AppiumDriver,
3+
createDriver,
4+
SearchOptions,
5+
elementHelper,
6+
} from "nativescript-dev-appium";
7+
8+
import { isOnTheLeft } from "./helpers/location";
9+
import { DriverWrapper, ExtendedUIElement } from "./helpers/appium-elements";
10+
11+
describe("Action Bar scenario", () => {
12+
let driver: AppiumDriver;
13+
let driverWrapper: DriverWrapper;
14+
15+
describe("dynamically add/remove ActionItems", async () => {
16+
let firstActionItem: ExtendedUIElement;
17+
let secondActionItem: ExtendedUIElement;
18+
let toggleFirstButton: ExtendedUIElement;
19+
let toggleSecondButton: ExtendedUIElement;
20+
21+
before(async () => {
22+
driver = await createDriver();
23+
driverWrapper = new DriverWrapper(driver);
24+
});
25+
26+
after(async () => {
27+
await driver.quit();
28+
console.log("Driver quits!");
29+
});
30+
31+
it("should navigate to page", async () => {
32+
const navigationButton =
33+
await driverWrapper.findElementByText("ActionBar dynamic", SearchOptions.exact);
34+
await navigationButton.click();
35+
36+
const actionBar =
37+
await driverWrapper.findElementByText("Action Bar Dynamic Items", SearchOptions.exact);
38+
});
39+
40+
it("should find elements", async () => {
41+
firstActionItem = await driverWrapper.findElementByText("one");
42+
secondActionItem = await driverWrapper.findElementByText("two");
43+
44+
toggleFirstButton = await driverWrapper.findElementByText("toggle 1");
45+
toggleSecondButton = await driverWrapper.findElementByText("toggle 2");
46+
});
47+
48+
it("should initially render the action items in the correct order", async () => {
49+
await checkOrderIsCorrect();
50+
});
51+
52+
it("should detach first element when its condition is false", done => {
53+
(async () => {
54+
await toggleFirst();
55+
56+
try {
57+
await driverWrapper.findElementByText("one", SearchOptions.exact);
58+
} catch (e) {
59+
done();
60+
}
61+
})();
62+
});
63+
64+
it("should attach first element in the correct position", async () => {
65+
await toggleFirst();
66+
await checkOrderIsCorrect();
67+
});
68+
69+
it("should detach second element when its condition is false", done => {
70+
(async () => {
71+
await toggleSecond();
72+
73+
try {
74+
await driverWrapper.findElementByText("two", SearchOptions.exact);
75+
} catch (e) {
76+
done();
77+
}
78+
})();
79+
});
80+
81+
it("should attach second element in the correct position", async () => {
82+
await toggleSecond();
83+
await checkOrderIsCorrect();
84+
});
85+
86+
it("should detach and then reattach both at correct places", async () => {
87+
await toggleFirst();
88+
await toggleSecond();
89+
90+
await toggleFirst();
91+
await toggleSecond();
92+
93+
await checkOrderIsCorrect();
94+
});
95+
96+
const checkOrderIsCorrect = async () => {
97+
await isOnTheLeft(firstActionItem, secondActionItem);
98+
};
99+
100+
const toggleFirst = async () => {
101+
toggleFirstButton = await toggleFirstButton.refetch();
102+
await toggleFirstButton.click();
103+
};
104+
105+
const toggleSecond = async () => {
106+
toggleSecondButton = await toggleSecondButton.refetch();
107+
await toggleSecondButton.click();
108+
};
109+
110+
});
111+
112+
describe("Action Bar extension with dynamic ActionItem", async () => {
113+
let toggleButton: ExtendedUIElement;
114+
let conditional: ExtendedUIElement;
115+
116+
before(async () => {
117+
driver = await createDriver();
118+
driverWrapper = new DriverWrapper(driver);
119+
});
120+
121+
after(async () => {
122+
await driver.quit();
123+
console.log("Driver quits!");
124+
});
125+
126+
it("should navigate to page", async () => {
127+
const navigationButton =
128+
await driverWrapper.findElementByText("ActionBarExtension", SearchOptions.exact);
129+
await navigationButton.click();
130+
});
131+
132+
it("should find elements", async () => {
133+
toggleButton = await driverWrapper.findElementByText("toggle");
134+
conditional = await driverWrapper.findElementByText("conditional");
135+
});
136+
137+
it("should detach conditional action item when its condition is false", done => {
138+
(async () => {
139+
await toggle();
140+
141+
try {
142+
await driverWrapper.findElementByText("conditional", SearchOptions.exact);
143+
} catch (e) {
144+
done();
145+
}
146+
})();
147+
});
148+
149+
it("should reattach conditional action item at correct place", async () => {
150+
await toggle();
151+
await checkOrderIsCorrect();
152+
});
153+
154+
const checkOrderIsCorrect = async () => {
155+
await isOnTheLeft(toggleButton, conditional);
156+
};
157+
158+
const toggle = async () => {
159+
toggleButton = await toggleButton.refetch();
160+
await toggleButton.click();
161+
};
162+
});
163+
});

‎e2e/renderer/e2e/helpers/appium-elements.ts

+21
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,25 @@ export class DriverWrapper {
3838

3939
return result;
4040
}
41+
42+
@refetchable()
43+
async findElementByXPath(...args: any[]): Promise<ExtendedUIElement> {
44+
const result = await (<any>this.driver).findElementByXPath(...args);
45+
46+
return result;
47+
}
48+
49+
@refetchable()
50+
async findElementsByXPath(...args: any[]): Promise<ExtendedUIElement[]> {
51+
const result = await (<any>this.driver).findElementsByXPath(...args);
52+
53+
return result || [];
54+
}
55+
56+
@refetchable()
57+
async findElementsByClassName(...args: any[]): Promise<ExtendedUIElement[]> {
58+
const result = await (<any>this.driver).findElementsByClassName(...args);
59+
60+
return result || [];
61+
}
4162
}

‎e2e/renderer/e2e/helpers/location.ts

+11
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@ export const isAbove = async (first: ExtendedUIElement, second: ExtendedUIElemen
1111

1212
assert.isTrue(firstY < secondY);
1313
}
14+
15+
export const isOnTheLeft = async (first: ExtendedUIElement, second: ExtendedUIElement) => {
16+
first = await first.refetch();
17+
second = await second.refetch();
18+
19+
const { x: firstX } = await first.location();
20+
const { x: secondX } = await second.location();
21+
22+
assert.isTrue(firstX < secondX);
23+
}
24+

0 commit comments

Comments
 (0)