mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
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
This commit is contained in:
1
e2e/ui-tests-app/.gitignore
vendored
1
e2e/ui-tests-app/.gitignore
vendored
@ -35,3 +35,4 @@ typings/
|
|||||||
# tests
|
# tests
|
||||||
mochawesome-report
|
mochawesome-report
|
||||||
e2e/resources/images/uitestsapp/*
|
e2e/resources/images/uitestsapp/*
|
||||||
|
testapp
|
@ -1,16 +1,15 @@
|
|||||||
import { AppiumDriver } from "nativescript-dev-appium";
|
import { AppiumDriver } from "nativescript-dev-appium";
|
||||||
import { ElementCacheStrategy } from "../../../helpers/navigation-helper";
|
|
||||||
import { TabNavigationBasePage } from "../tab-navigation-base-page";
|
import { TabNavigationBasePage } from "../tab-navigation-base-page";
|
||||||
|
import { NsCapabilities } from "nativescript-dev-appium/lib/ns-capabilities";
|
||||||
|
import { AutomationName } from "nativescript-dev-appium/lib/automation-name";
|
||||||
|
|
||||||
export class BottomNavigationBasePage extends TabNavigationBasePage {
|
export class BottomNavigationBasePage extends TabNavigationBasePage {
|
||||||
private readonly mainWidgetXPath: string;
|
private mainWidgetXPath: string;
|
||||||
constructor(_driver: AppiumDriver) {
|
constructor(_driver: AppiumDriver) {
|
||||||
super(_driver, ["bottom-navigation"]);
|
super(_driver, ["bottom-navigation"]);
|
||||||
this.mainWidgetXPath = this._driver.isIOS ?
|
this.loadMainWidgetXpath();
|
||||||
`//XCUIElementTypeOther[@name="tabNavigation"]/XCUIElementTypeTabBar`
|
|
||||||
: `//android.view.ViewGroup[@content-desc="tabNavigation"]/android.widget.LinearLayout/android.widget.LinearLayout`;
|
|
||||||
}
|
}
|
||||||
//android.view.ViewGroup[@content-desc="tabNavigation"]/android.widget.LinearLayout/android.widget.LinearLayout/*
|
|
||||||
async getItems() {
|
async getItems() {
|
||||||
return await this._driver.findElementsByXPath(`${this.mainWidgetXPath}/*`);
|
return await this._driver.findElementsByXPath(`${this.mainWidgetXPath}/*`);
|
||||||
}
|
}
|
||||||
@ -18,4 +17,18 @@ export class BottomNavigationBasePage extends TabNavigationBasePage {
|
|||||||
async mainWidget() {
|
async mainWidget() {
|
||||||
return await this._driver.findElementByXPath(this.mainWidgetXPath);
|
return await this._driver.findElementByXPath(this.mainWidgetXPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private loadMainWidgetXpath() {
|
||||||
|
const automationName = (<NsCapabilities>this._driver.nsCapabilities).automationName;
|
||||||
|
if (this._driver.isAndroid
|
||||||
|
&& automationName === AutomationName.UiAutomator1 || automationName === AutomationName.Appium) {
|
||||||
|
this.mainWidgetXPath = `//android.view.View[@content-desc="tabNavigation"]/android.widget.LinearLayout/android.widget.LinearLayout`;
|
||||||
|
} else if (this._driver.isAndroid && automationName === AutomationName.UiAutomator2) {
|
||||||
|
this.mainWidgetXPath = `//android.view.ViewGroup[@content-desc="tabNavigation"]/android.widget.LinearLayout/android.widget.LinearLayout`;
|
||||||
|
} else if (this._driver.isIOS) {
|
||||||
|
this.mainWidgetXPath = `//XCUIElementTypeOther[@name="tabNavigation"]/XCUIElementTypeTabBar`;
|
||||||
|
} else {
|
||||||
|
throw new Error("Run type is missing! Please, check appium settings and run test again!");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -100,8 +100,8 @@ describe(`${suite}-${spec}-suite`, async function () {
|
|||||||
|
|
||||||
// add items
|
// add items
|
||||||
const addTabBtn = await driver.waitForElement("add-tab");
|
const addTabBtn = await driver.waitForElement("add-tab");
|
||||||
await addTabBtn.tap();
|
await addTabBtn.click();
|
||||||
await addTabBtn.tap();
|
await addTabBtn.click();
|
||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
|
|
||||||
await bottomNavigationBasePage.refreshTabItems();
|
await bottomNavigationBasePage.refreshTabItems();
|
||||||
@ -118,7 +118,7 @@ describe(`${suite}-${spec}-suite`, async function () {
|
|||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
|
|
||||||
const goToSecondBtn = await driver.waitForElement("goToSecond");
|
const goToSecondBtn = await driver.waitForElement("goToSecond");
|
||||||
await goToSecondBtn.tap();
|
await goToSecondBtn.click();
|
||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
|
|
||||||
await bottomNavigationBasePage.tabOnItem(1);
|
await bottomNavigationBasePage.tabOnItem(1);
|
||||||
@ -157,7 +157,7 @@ describe(`${suite}-${spec}-suite`, async function () {
|
|||||||
|
|
||||||
let selectSecondTabFromCodeBehind = await driver.waitForElement("selectSecondTab");
|
let selectSecondTabFromCodeBehind = await driver.waitForElement("selectSecondTab");
|
||||||
logInfo(`Click on "select second tab button"`);
|
logInfo(`Click on "select second tab button"`);
|
||||||
await selectSecondTabFromCodeBehind.tap();
|
await selectSecondTabFromCodeBehind.click();
|
||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
|
|
||||||
await driver.backgroundApp(1);
|
await driver.backgroundApp(1);
|
||||||
@ -168,7 +168,7 @@ describe(`${suite}-${spec}-suite`, async function () {
|
|||||||
|
|
||||||
selectSecondTabFromCodeBehind = await driver.waitForElement("selectSecondTab");
|
selectSecondTabFromCodeBehind = await driver.waitForElement("selectSecondTab");
|
||||||
logInfo(`Click on "select second tab button"`);
|
logInfo(`Click on "select second tab button"`);
|
||||||
await selectSecondTabFromCodeBehind.tap();
|
await selectSecondTabFromCodeBehind.click();
|
||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
|
|
||||||
await driver.backgroundApp(1);
|
await driver.backgroundApp(1);
|
||||||
@ -190,10 +190,21 @@ describe(`${suite}-${spec}-suite`, async function () {
|
|||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
|
|
||||||
await driver.backgroundApp(1);
|
await driver.backgroundApp(1);
|
||||||
|
if (driver.isAndroid) {
|
||||||
|
driver.imageHelper.resetDefaultOptions();
|
||||||
|
}
|
||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
|
|
||||||
// await driver.setOrientation(DeviceOrientation.PORTRAIT);
|
await driver.setOrientation(DeviceOrientation.PORTRAIT);
|
||||||
|
if (driver.isAndroid) {
|
||||||
|
await driver.imageHelper.compareScreen(
|
||||||
|
{
|
||||||
|
imageName: "tab-navigation-bottom-navigation-fancy-fonts-change-orientation_2.png",
|
||||||
|
keepOriginalImageName: true
|
||||||
|
});
|
||||||
|
} else {
|
||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
|
}
|
||||||
|
|
||||||
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
|
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
|
||||||
await bottomNavigationBasePage.navigateBackToSuitMainPage();
|
await bottomNavigationBasePage.navigateBackToSuitMainPage();
|
||||||
|
@ -3,7 +3,7 @@ import { PageObjectBaseModel } from "../../page-object-base-model";
|
|||||||
import { ElementCacheStrategy } from "../../helpers/navigation-helper";
|
import { ElementCacheStrategy } from "../../helpers/navigation-helper";
|
||||||
|
|
||||||
export abstract class TabNavigationBasePage extends PageObjectBaseModel {
|
export abstract class TabNavigationBasePage extends PageObjectBaseModel {
|
||||||
protected bottomNavigatioinTabRect: IRectangle;
|
protected bottomNavigationTabRect: IRectangle;
|
||||||
protected bottomNavigationItems: Array<UIElement>;
|
protected bottomNavigationItems: Array<UIElement>;
|
||||||
protected bottomNavigationItemsRects: Map<number, Point> = new Map();
|
protected bottomNavigationItemsRects: Map<number, Point> = new Map();
|
||||||
|
|
||||||
@ -34,8 +34,8 @@ export abstract class TabNavigationBasePage extends PageObjectBaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async refreshTabWidget() {
|
async refreshTabWidget() {
|
||||||
const bottomNavigatioinTab = await this.mainWidget();
|
const bottomNavigationTab = await this.mainWidget();
|
||||||
this.bottomNavigatioinTabRect = await bottomNavigatioinTab.getRectangle();
|
this.bottomNavigationTabRect = await bottomNavigationTab.getRectangle();
|
||||||
}
|
}
|
||||||
|
|
||||||
async tabOnItem(index: number) {
|
async tabOnItem(index: number) {
|
||||||
@ -59,11 +59,19 @@ export abstract class TabNavigationBasePage extends PageObjectBaseModel {
|
|||||||
endPoint.x = this._driver.nsCapabilities.device.viewportRect.x / this._driver.nsCapabilities.device.config.density;
|
endPoint.x = this._driver.nsCapabilities.device.viewportRect.x / this._driver.nsCapabilities.device.config.density;
|
||||||
endPoint.y = startPoint.y;
|
endPoint.y = startPoint.y;
|
||||||
} else {
|
} else {
|
||||||
|
if (this._driver.nsCapabilities.device.viewportRect) {
|
||||||
startPoint.x = this._driver.nsCapabilities.device.viewportRect.width - 5;
|
startPoint.x = this._driver.nsCapabilities.device.viewportRect.width - 5;
|
||||||
startPoint.y = this._driver.nsCapabilities.device.viewportRect.y
|
startPoint.y = this._driver.nsCapabilities.device.viewportRect.y
|
||||||
+ this._driver.nsCapabilities.device.viewportRect.height / 2;
|
+ this._driver.nsCapabilities.device.viewportRect.height / 2;
|
||||||
endPoint.x = this._driver.nsCapabilities.device.viewportRect.x + 5;
|
endPoint.x = this._driver.nsCapabilities.device.viewportRect.x + 5;
|
||||||
endPoint.y = startPoint.y;
|
endPoint.y = startPoint.y;
|
||||||
|
} else {
|
||||||
|
startPoint.x = this._driver.imageHelper.options.cropRectangle.width - 5;
|
||||||
|
startPoint.y = this._driver.imageHelper.options.cropRectangle.y
|
||||||
|
+ this._driver.imageHelper.options.cropRectangle.height / 2;
|
||||||
|
endPoint.x = this._driver.imageHelper.options.cropRectangle.x + 5;
|
||||||
|
endPoint.y = startPoint.y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await this._driver.swipe(startPoint, endPoint);
|
await this._driver.swipe(startPoint, endPoint);
|
||||||
|
@ -72,12 +72,12 @@ describe(`${suite}-${spec}-suite`, async function () {
|
|||||||
|
|
||||||
await driver.swipe(
|
await driver.swipe(
|
||||||
{
|
{
|
||||||
x: driver.nsCapabilities.device.viewportRect.width + driver.nsCapabilities.device.viewportRect.x - 10,
|
x: driver.imageHelper.options.cropRectangle.width + driver.imageHelper.options.cropRectangle.x - 10,
|
||||||
y: driver.nsCapabilities.device.viewportRect.height / 2
|
y: driver.imageHelper.options.cropRectangle.height / 2
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
y: 0,
|
y: 0,
|
||||||
x: driver.nsCapabilities.device.viewportRect.x + 10
|
x: driver.imageHelper.options.cropRectangle.x + 10
|
||||||
}
|
}
|
||||||
, 100);
|
, 100);
|
||||||
await driver.imageHelper.compareScreen({ timeOutSeconds: 5, tolerance: 0.01 });
|
await driver.imageHelper.compareScreen({ timeOutSeconds: 5, tolerance: 0.01 });
|
||||||
@ -101,11 +101,11 @@ describe(`${suite}-${spec}-suite`, async function () {
|
|||||||
|
|
||||||
const tabItemLocator = driver.isAndroid ? driver.locators.image : driver.locators.getElementByName("imagebutton");
|
const tabItemLocator = driver.isAndroid ? driver.locators.image : driver.locators.getElementByName("imagebutton");
|
||||||
let btns = await driver.findElementsByClassName(tabItemLocator, 5000);
|
let btns = await driver.findElementsByClassName(tabItemLocator, 5000);
|
||||||
await btns[index].tap();
|
await btns[index].click();
|
||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
|
|
||||||
btns = await driver.findElementsByClassName(tabItemLocator, 5000);
|
btns = await driver.findElementsByClassName(tabItemLocator, 5000);
|
||||||
await btns[index - 1].tap();
|
await btns[index - 1].click();
|
||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
|
|
||||||
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
|
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
|
||||||
@ -235,10 +235,10 @@ describe(`${suite}-${spec}-suite`, async function () {
|
|||||||
await tabViewBasePage.navigateToSample("text-transform");
|
await tabViewBasePage.navigateToSample("text-transform");
|
||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
|
|
||||||
await (await driver.waitForElement("apply")).tap();
|
await (await driver.waitForElement("apply")).click();
|
||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
|
|
||||||
await (await driver.waitForElement("reset")).tap();
|
await (await driver.waitForElement("reset")).click();
|
||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
|
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
|
||||||
|
|
||||||
|
@ -67,19 +67,19 @@ describe(`${suite}-${spec}-suite`, async function () {
|
|||||||
|
|
||||||
}
|
}
|
||||||
const scenarioBtn = await driver.waitForElement(sample.sample);
|
const scenarioBtn = await driver.waitForElement(sample.sample);
|
||||||
await scenarioBtn.tap();
|
await scenarioBtn.click();
|
||||||
imageName = setImageName(suite, spec, imageName);
|
imageName = setImageName(suite, spec, imageName);
|
||||||
await driver.imageHelper.compareScreen({ imageName: imageName, timeOutSeconds: 5, tolerance: 0, toleranceType: ImageOptions.pixel });
|
await driver.imageHelper.compareScreen({ imageName: imageName, timeOutSeconds: 5, tolerance: 0, toleranceType: ImageOptions.pixel });
|
||||||
const tabTwo = await driver.waitForElement(sample.tab2);
|
const tabTwo = await driver.waitForElement(sample.tab2);
|
||||||
await tabTwo.click();
|
await tabTwo.click();
|
||||||
await driver.imageHelper.compareScreen({ imageName: imageName, timeOutSeconds: 5 });
|
await driver.imageHelper.compareScreen({ imageName: imageName, timeOutSeconds: 5 });
|
||||||
|
|
||||||
const imageComparissonresult = driver.imageHelper.hasImageComparisonPassed();
|
const imageComparisonResult = driver.imageHelper.hasImageComparisonPassed();
|
||||||
assert.isTrue(imageComparissonresult);
|
assert.isTrue(imageComparisonResult);
|
||||||
|
|
||||||
if (imageComparissonresult) {
|
if (imageComparisonResult) {
|
||||||
const tabOne = await driver.waitForElement(sample.tab1);
|
const tabOne = await driver.waitForElement(sample.tab1);
|
||||||
await tabOne.tap();
|
await tabOne.click();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ import { nsCapabilities, createDriver, AppiumDriver } from "nativescript-dev-app
|
|||||||
import { TabsViewBasePage } from "./tabs-view-base-page";
|
import { TabsViewBasePage } from "./tabs-view-base-page";
|
||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
import { setImageName } from "../../../helpers/image-helper";
|
import { setImageName } from "../../../helpers/image-helper";
|
||||||
|
import { NsCapabilities } from "nativescript-dev-appium/lib/ns-capabilities";
|
||||||
|
import { AutomationName } from "nativescript-dev-appium/lib/automation-name";
|
||||||
|
|
||||||
const suite = "tab-navigation";
|
const suite = "tab-navigation";
|
||||||
const spec = "tabs";
|
const spec = "tabs";
|
||||||
@ -81,7 +83,12 @@ describe(`${imagePrefix}-suite`, async function () {
|
|||||||
await tabsViewBasePage.tabOnItem(1);
|
await tabsViewBasePage.tabOnItem(1);
|
||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
|
|
||||||
|
if (driver.isAndroid && (<NsCapabilities>driver.nsCapabilities).automationName === AutomationName.UiAutomator1
|
||||||
|
|| driver.isAndroid && (<NsCapabilities>driver.nsCapabilities).automationName === AutomationName.Appium) {
|
||||||
|
await tabsViewBasePage.tabOnItem(1);
|
||||||
|
} else {
|
||||||
await tabsViewBasePage.tabOnItem(2);
|
await tabsViewBasePage.tabOnItem(2);
|
||||||
|
}
|
||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
|
|
||||||
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
|
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
|
||||||
@ -226,8 +233,8 @@ describe(`${imagePrefix}-suite`, async function () {
|
|||||||
|
|
||||||
// add items
|
// add items
|
||||||
const addTabBtn = await driver.waitForElement("add-tab");
|
const addTabBtn = await driver.waitForElement("add-tab");
|
||||||
await addTabBtn.tap();
|
await addTabBtn.click();
|
||||||
await addTabBtn.tap();
|
await addTabBtn.click();
|
||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
|
|
||||||
await tabsViewBasePage.refreshTabItems();
|
await tabsViewBasePage.refreshTabItems();
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import { AppiumDriver } from "nativescript-dev-appium";
|
import { AppiumDriver } from "nativescript-dev-appium";
|
||||||
import { TabNavigationBasePage } from "../tab-navigation-base-page";
|
import { TabNavigationBasePage } from "../tab-navigation-base-page";
|
||||||
|
import { NsCapabilities } from "nativescript-dev-appium/lib/ns-capabilities";
|
||||||
|
import { AutomationName } from "nativescript-dev-appium/lib/automation-name";
|
||||||
|
|
||||||
export class TabsViewBasePage extends TabNavigationBasePage {
|
export class TabsViewBasePage extends TabNavigationBasePage {
|
||||||
private readonly mainWidgetXPath: string;
|
private mainWidgetXPath: string;
|
||||||
constructor(_driver: AppiumDriver) {
|
constructor(_driver: AppiumDriver) {
|
||||||
super(_driver, ["tabs"]);
|
super(_driver, ["tabs"]);
|
||||||
this.mainWidgetXPath = this._driver.isIOS ?
|
this.loadMainWidgetXpath();
|
||||||
`//XCUIElementTypeOther[@name="tabNavigation"]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeCollectionView`
|
|
||||||
: `//android.view.ViewGroup[@content-desc="tabNavigation"]/android.widget.HorizontalScrollView/android.widget.LinearLayout`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getItems() {
|
async getItems() {
|
||||||
@ -22,4 +22,18 @@ export class TabsViewBasePage extends TabNavigationBasePage {
|
|||||||
async mainWidget() {
|
async mainWidget() {
|
||||||
return await this._driver.findElementByXPath(this.mainWidgetXPath);
|
return await this._driver.findElementByXPath(this.mainWidgetXPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private loadMainWidgetXpath() {
|
||||||
|
const automationName = (<NsCapabilities>this._driver.nsCapabilities).automationName;
|
||||||
|
if (this._driver.isAndroid
|
||||||
|
&& automationName === AutomationName.UiAutomator1 || automationName === AutomationName.Appium) {
|
||||||
|
this.mainWidgetXPath = `//android.view.View[@content-desc="tabNavigation"]/android.widget.HorizontalScrollView/android.widget.LinearLayout`;
|
||||||
|
} else if (this._driver.isAndroid && automationName === AutomationName.UiAutomator2) {
|
||||||
|
this.mainWidgetXPath = `//android.view.ViewGroup[@content-desc="tabNavigation"]/android.widget.HorizontalScrollView/android.widget.LinearLayout`;
|
||||||
|
} else if (this._driver.isIOS) {
|
||||||
|
this.mainWidgetXPath = `//XCUIElementTypeOther[@name="tabNavigation"]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeCollectionView`;
|
||||||
|
} else {
|
||||||
|
throw new Error("Run type is missing! Please, check appium settings and run test again!");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user