Skip to content

Commit 589bb43

Browse files
tests: fix tab-navigation-tests for android api level < 23 (#7675)
* tests: fix tab-navigation-tests for android api level < 23 * chore: remove depricated "tap()" method * chore: fix tslint * chore: replace api check with automation name check * chore: relpace check 'ryGetApiLevel()' with automation name
1 parent 458cb59 commit 589bb43

File tree

8 files changed

+97
-43
lines changed

8 files changed

+97
-43
lines changed

e2e/ui-tests-app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ typings/
3535
# tests
3636
mochawesome-report
3737
e2e/resources/images/uitestsapp/*
38+
testapp
Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
import { AppiumDriver } from "nativescript-dev-appium";
2-
import { ElementCacheStrategy } from "../../../helpers/navigation-helper";
32
import { TabNavigationBasePage } from "../tab-navigation-base-page";
3+
import { NsCapabilities } from "nativescript-dev-appium/lib/ns-capabilities";
4+
import { AutomationName } from "nativescript-dev-appium/lib/automation-name";
45

56
export class BottomNavigationBasePage extends TabNavigationBasePage {
6-
private readonly mainWidgetXPath: string;
7+
private mainWidgetXPath: string;
78
constructor(_driver: AppiumDriver) {
89
super(_driver, ["bottom-navigation"]);
9-
this.mainWidgetXPath = this._driver.isIOS ?
10-
`//XCUIElementTypeOther[@name="tabNavigation"]/XCUIElementTypeTabBar`
11-
: `//android.view.ViewGroup[@content-desc="tabNavigation"]/android.widget.LinearLayout/android.widget.LinearLayout`;
10+
this.loadMainWidgetXpath();
1211
}
13-
//android.view.ViewGroup[@content-desc="tabNavigation"]/android.widget.LinearLayout/android.widget.LinearLayout/*
12+
1413
async getItems() {
1514
return await this._driver.findElementsByXPath(`${this.mainWidgetXPath}/*`);
1615
}
1716

1817
async mainWidget() {
1918
return await this._driver.findElementByXPath(this.mainWidgetXPath);
2019
}
20+
21+
private loadMainWidgetXpath() {
22+
const automationName = (<NsCapabilities>this._driver.nsCapabilities).automationName;
23+
if (this._driver.isAndroid
24+
&& automationName === AutomationName.UiAutomator1 || automationName === AutomationName.Appium) {
25+
this.mainWidgetXPath = `//android.view.View[@content-desc="tabNavigation"]/android.widget.LinearLayout/android.widget.LinearLayout`;
26+
} else if (this._driver.isAndroid && automationName === AutomationName.UiAutomator2) {
27+
this.mainWidgetXPath = `//android.view.ViewGroup[@content-desc="tabNavigation"]/android.widget.LinearLayout/android.widget.LinearLayout`;
28+
} else if (this._driver.isIOS) {
29+
this.mainWidgetXPath = `//XCUIElementTypeOther[@name="tabNavigation"]/XCUIElementTypeTabBar`;
30+
} else {
31+
throw new Error("Run type is missing! Please, check appium settings and run test again!");
32+
}
33+
}
2134
}

e2e/ui-tests-app/e2e/suites/tab-navigation/bottom-navigation/bottom-navigation.e2e-spec.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe(`${suite}-${spec}-suite`, async function () {
4444

4545
await bottomNavigationBasePage.tabOnItem(1);
4646
await driver.imageHelper.compareScreen();
47-
47+
4848
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
4949

5050
await bottomNavigationBasePage.navigateBackToSuitMainPage();
@@ -100,8 +100,8 @@ describe(`${suite}-${spec}-suite`, async function () {
100100

101101
// add items
102102
const addTabBtn = await driver.waitForElement("add-tab");
103-
await addTabBtn.tap();
104-
await addTabBtn.tap();
103+
await addTabBtn.click();
104+
await addTabBtn.click();
105105
await driver.imageHelper.compareScreen();
106106

107107
await bottomNavigationBasePage.refreshTabItems();
@@ -118,7 +118,7 @@ describe(`${suite}-${spec}-suite`, async function () {
118118
await driver.imageHelper.compareScreen();
119119

120120
const goToSecondBtn = await driver.waitForElement("goToSecond");
121-
await goToSecondBtn.tap();
121+
await goToSecondBtn.click();
122122
await driver.imageHelper.compareScreen();
123123

124124
await bottomNavigationBasePage.tabOnItem(1);
@@ -157,7 +157,7 @@ describe(`${suite}-${spec}-suite`, async function () {
157157

158158
let selectSecondTabFromCodeBehind = await driver.waitForElement("selectSecondTab");
159159
logInfo(`Click on "select second tab button"`);
160-
await selectSecondTabFromCodeBehind.tap();
160+
await selectSecondTabFromCodeBehind.click();
161161
await driver.imageHelper.compareScreen();
162162

163163
await driver.backgroundApp(1);
@@ -168,7 +168,7 @@ describe(`${suite}-${spec}-suite`, async function () {
168168

169169
selectSecondTabFromCodeBehind = await driver.waitForElement("selectSecondTab");
170170
logInfo(`Click on "select second tab button"`);
171-
await selectSecondTabFromCodeBehind.tap();
171+
await selectSecondTabFromCodeBehind.click();
172172
await driver.imageHelper.compareScreen();
173173

174174
await driver.backgroundApp(1);
@@ -190,10 +190,21 @@ describe(`${suite}-${spec}-suite`, async function () {
190190
await driver.imageHelper.compareScreen();
191191

192192
await driver.backgroundApp(1);
193+
if (driver.isAndroid) {
194+
driver.imageHelper.resetDefaultOptions();
195+
}
193196
await driver.imageHelper.compareScreen();
194197

195-
// await driver.setOrientation(DeviceOrientation.PORTRAIT);
196-
await driver.imageHelper.compareScreen();
198+
await driver.setOrientation(DeviceOrientation.PORTRAIT);
199+
if (driver.isAndroid) {
200+
await driver.imageHelper.compareScreen(
201+
{
202+
imageName: "tab-navigation-bottom-navigation-fancy-fonts-change-orientation_2.png",
203+
keepOriginalImageName: true
204+
});
205+
} else {
206+
await driver.imageHelper.compareScreen();
207+
}
197208

198209
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
199210
await bottomNavigationBasePage.navigateBackToSuitMainPage();

e2e/ui-tests-app/e2e/suites/tab-navigation/tab-navigation-base-page.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { PageObjectBaseModel } from "../../page-object-base-model";
33
import { ElementCacheStrategy } from "../../helpers/navigation-helper";
44

55
export abstract class TabNavigationBasePage extends PageObjectBaseModel {
6-
protected bottomNavigatioinTabRect: IRectangle;
6+
protected bottomNavigationTabRect: IRectangle;
77
protected bottomNavigationItems: Array<UIElement>;
88
protected bottomNavigationItemsRects: Map<number, Point> = new Map();
99

@@ -34,8 +34,8 @@ export abstract class TabNavigationBasePage extends PageObjectBaseModel {
3434
}
3535

3636
async refreshTabWidget() {
37-
const bottomNavigatioinTab = await this.mainWidget();
38-
this.bottomNavigatioinTabRect = await bottomNavigatioinTab.getRectangle();
37+
const bottomNavigationTab = await this.mainWidget();
38+
this.bottomNavigationTabRect = await bottomNavigationTab.getRectangle();
3939
}
4040

4141
async tabOnItem(index: number) {
@@ -52,18 +52,26 @@ export abstract class TabNavigationBasePage extends PageObjectBaseModel {
5252
const endPoint = <Point>{};
5353

5454
if (this._driver.isIOS) {
55-
startPoint.x = (this._driver.nsCapabilities.device.viewportRect.x / this._driver.nsCapabilities.device.config.density
55+
startPoint.x = (this._driver.nsCapabilities.device.viewportRect.x / this._driver.nsCapabilities.device.config.density
5656
+ this._driver.nsCapabilities.device.viewportRect.width / this._driver.nsCapabilities.device.config.density);
5757
startPoint.y = this._driver.nsCapabilities.device.viewportRect.y / this._driver.nsCapabilities.device.config.density
5858
+ (this._driver.nsCapabilities.device.viewportRect.height / this._driver.nsCapabilities.device.config.density) / 2;
5959
endPoint.x = this._driver.nsCapabilities.device.viewportRect.x / this._driver.nsCapabilities.device.config.density;
6060
endPoint.y = startPoint.y;
6161
} else {
62-
startPoint.x = this._driver.nsCapabilities.device.viewportRect.width - 5;
63-
startPoint.y = this._driver.nsCapabilities.device.viewportRect.y
64-
+ this._driver.nsCapabilities.device.viewportRect.height / 2;
65-
endPoint.x = this._driver.nsCapabilities.device.viewportRect.x + 5;
66-
endPoint.y = startPoint.y;
62+
if (this._driver.nsCapabilities.device.viewportRect) {
63+
startPoint.x = this._driver.nsCapabilities.device.viewportRect.width - 5;
64+
startPoint.y = this._driver.nsCapabilities.device.viewportRect.y
65+
+ this._driver.nsCapabilities.device.viewportRect.height / 2;
66+
endPoint.x = this._driver.nsCapabilities.device.viewportRect.x + 5;
67+
endPoint.y = startPoint.y;
68+
} else {
69+
startPoint.x = this._driver.imageHelper.options.cropRectangle.width - 5;
70+
startPoint.y = this._driver.imageHelper.options.cropRectangle.y
71+
+ this._driver.imageHelper.options.cropRectangle.height / 2;
72+
endPoint.x = this._driver.imageHelper.options.cropRectangle.x + 5;
73+
endPoint.y = startPoint.y;
74+
}
6775
}
6876

6977
await this._driver.swipe(startPoint, endPoint);

e2e/ui-tests-app/e2e/suites/tab-navigation/tab-view/tab-view-common-tests.e2e-spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ describe(`${suite}-${spec}-suite`, async function () {
7272

7373
await driver.swipe(
7474
{
75-
x: driver.nsCapabilities.device.viewportRect.width + driver.nsCapabilities.device.viewportRect.x - 10,
76-
y: driver.nsCapabilities.device.viewportRect.height / 2
75+
x: driver.imageHelper.options.cropRectangle.width + driver.imageHelper.options.cropRectangle.x - 10,
76+
y: driver.imageHelper.options.cropRectangle.height / 2
7777
},
7878
{
7979
y: 0,
80-
x: driver.nsCapabilities.device.viewportRect.x + 10
80+
x: driver.imageHelper.options.cropRectangle.x + 10
8181
}
8282
, 100);
8383
await driver.imageHelper.compareScreen({ timeOutSeconds: 5, tolerance: 0.01 });
@@ -101,11 +101,11 @@ describe(`${suite}-${spec}-suite`, async function () {
101101

102102
const tabItemLocator = driver.isAndroid ? driver.locators.image : driver.locators.getElementByName("imagebutton");
103103
let btns = await driver.findElementsByClassName(tabItemLocator, 5000);
104-
await btns[index].tap();
104+
await btns[index].click();
105105
await driver.imageHelper.compareScreen();
106106

107107
btns = await driver.findElementsByClassName(tabItemLocator, 5000);
108-
await btns[index - 1].tap();
108+
await btns[index - 1].click();
109109
await driver.imageHelper.compareScreen();
110110

111111
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
@@ -235,10 +235,10 @@ describe(`${suite}-${spec}-suite`, async function () {
235235
await tabViewBasePage.navigateToSample("text-transform");
236236
await driver.imageHelper.compareScreen();
237237

238-
await (await driver.waitForElement("apply")).tap();
238+
await (await driver.waitForElement("apply")).click();
239239
await driver.imageHelper.compareScreen();
240240

241-
await (await driver.waitForElement("reset")).tap();
241+
await (await driver.waitForElement("reset")).click();
242242
await driver.imageHelper.compareScreen();
243243
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
244244

e2e/ui-tests-app/e2e/suites/tab-navigation/tab-view/tab-view-css-properties.e2e-spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,19 @@ describe(`${suite}-${spec}-suite`, async function () {
6767

6868
}
6969
const scenarioBtn = await driver.waitForElement(sample.sample);
70-
await scenarioBtn.tap();
70+
await scenarioBtn.click();
7171
imageName = setImageName(suite, spec, imageName);
7272
await driver.imageHelper.compareScreen({ imageName: imageName, timeOutSeconds: 5, tolerance: 0, toleranceType: ImageOptions.pixel });
7373
const tabTwo = await driver.waitForElement(sample.tab2);
7474
await tabTwo.click();
7575
await driver.imageHelper.compareScreen({ imageName: imageName, timeOutSeconds: 5 });
7676

77-
const imageComparissonresult = driver.imageHelper.hasImageComparisonPassed();
78-
assert.isTrue(imageComparissonresult);
77+
const imageComparisonResult = driver.imageHelper.hasImageComparisonPassed();
78+
assert.isTrue(imageComparisonResult);
7979

80-
if (imageComparissonresult) {
80+
if (imageComparisonResult) {
8181
const tabOne = await driver.waitForElement(sample.tab1);
82-
await tabOne.tap();
82+
await tabOne.click();
8383
}
8484
});
8585
}

e2e/ui-tests-app/e2e/suites/tab-navigation/tabs/tabs-tests.e2e-spec.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { nsCapabilities, createDriver, AppiumDriver } from "nativescript-dev-app
22
import { TabsViewBasePage } from "./tabs-view-base-page";
33
import { assert } from "chai";
44
import { setImageName } from "../../../helpers/image-helper";
5+
import { NsCapabilities } from "nativescript-dev-appium/lib/ns-capabilities";
6+
import { AutomationName } from "nativescript-dev-appium/lib/automation-name";
57

68
const suite = "tab-navigation";
79
const spec = "tabs";
@@ -81,7 +83,12 @@ describe(`${imagePrefix}-suite`, async function () {
8183
await tabsViewBasePage.tabOnItem(1);
8284
await driver.imageHelper.compareScreen();
8385

84-
await tabsViewBasePage.tabOnItem(2);
86+
if (driver.isAndroid && (<NsCapabilities>driver.nsCapabilities).automationName === AutomationName.UiAutomator1
87+
|| driver.isAndroid && (<NsCapabilities>driver.nsCapabilities).automationName === AutomationName.Appium) {
88+
await tabsViewBasePage.tabOnItem(1);
89+
} else {
90+
await tabsViewBasePage.tabOnItem(2);
91+
}
8592
await driver.imageHelper.compareScreen();
8693

8794
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
@@ -226,8 +233,8 @@ describe(`${imagePrefix}-suite`, async function () {
226233

227234
// add items
228235
const addTabBtn = await driver.waitForElement("add-tab");
229-
await addTabBtn.tap();
230-
await addTabBtn.tap();
236+
await addTabBtn.click();
237+
await addTabBtn.click();
231238
await driver.imageHelper.compareScreen();
232239

233240
await tabsViewBasePage.refreshTabItems();
Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
11
import { AppiumDriver } from "nativescript-dev-appium";
22
import { TabNavigationBasePage } from "../tab-navigation-base-page";
3+
import { NsCapabilities } from "nativescript-dev-appium/lib/ns-capabilities";
4+
import { AutomationName } from "nativescript-dev-appium/lib/automation-name";
35

46
export class TabsViewBasePage extends TabNavigationBasePage {
5-
private readonly mainWidgetXPath: string;
7+
private mainWidgetXPath: string;
68
constructor(_driver: AppiumDriver) {
79
super(_driver, ["tabs"]);
8-
this.mainWidgetXPath = this._driver.isIOS ?
9-
`//XCUIElementTypeOther[@name="tabNavigation"]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeCollectionView`
10-
: `//android.view.ViewGroup[@content-desc="tabNavigation"]/android.widget.HorizontalScrollView/android.widget.LinearLayout`;
10+
this.loadMainWidgetXpath();
1111
}
1212

1313
async getItems() {
1414
const items = await this._driver.findElementsByXPath(`${this.mainWidgetXPath}/*`);
1515
if (this._driver.isIOS) {
1616
items.shift();
1717
}
18-
18+
1919
return items;
2020
}
2121

2222
async mainWidget() {
2323
return await this._driver.findElementByXPath(this.mainWidgetXPath);
2424
}
25+
26+
private loadMainWidgetXpath() {
27+
const automationName = (<NsCapabilities>this._driver.nsCapabilities).automationName;
28+
if (this._driver.isAndroid
29+
&& automationName === AutomationName.UiAutomator1 || automationName === AutomationName.Appium) {
30+
this.mainWidgetXPath = `//android.view.View[@content-desc="tabNavigation"]/android.widget.HorizontalScrollView/android.widget.LinearLayout`;
31+
} else if (this._driver.isAndroid && automationName === AutomationName.UiAutomator2) {
32+
this.mainWidgetXPath = `//android.view.ViewGroup[@content-desc="tabNavigation"]/android.widget.HorizontalScrollView/android.widget.LinearLayout`;
33+
} else if (this._driver.isIOS) {
34+
this.mainWidgetXPath = `//XCUIElementTypeOther[@name="tabNavigation"]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeCollectionView`;
35+
} else {
36+
throw new Error("Run type is missing! Please, check appium settings and run test again!");
37+
}
38+
}
2539
}

0 commit comments

Comments
 (0)