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:
Svetoslav
2019-08-14 04:13:29 +03:00
committed by GitHub
parent 458cb59472
commit 589bb438bf
8 changed files with 97 additions and 43 deletions

View File

@ -35,3 +35,4 @@ typings/
# tests
mochawesome-report
e2e/resources/images/uitestsapp/*
testapp

View File

@ -1,16 +1,15 @@
import { AppiumDriver } from "nativescript-dev-appium";
import { ElementCacheStrategy } from "../../../helpers/navigation-helper";
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 {
private readonly mainWidgetXPath: string;
private mainWidgetXPath: string;
constructor(_driver: AppiumDriver) {
super(_driver, ["bottom-navigation"]);
this.mainWidgetXPath = this._driver.isIOS ?
`//XCUIElementTypeOther[@name="tabNavigation"]/XCUIElementTypeTabBar`
: `//android.view.ViewGroup[@content-desc="tabNavigation"]/android.widget.LinearLayout/android.widget.LinearLayout`;
this.loadMainWidgetXpath();
}
//android.view.ViewGroup[@content-desc="tabNavigation"]/android.widget.LinearLayout/android.widget.LinearLayout/*
async getItems() {
return await this._driver.findElementsByXPath(`${this.mainWidgetXPath}/*`);
}
@ -18,4 +17,18 @@ export class BottomNavigationBasePage extends TabNavigationBasePage {
async mainWidget() {
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!");
}
}
}

View File

@ -100,8 +100,8 @@ describe(`${suite}-${spec}-suite`, async function () {
// add items
const addTabBtn = await driver.waitForElement("add-tab");
await addTabBtn.tap();
await addTabBtn.tap();
await addTabBtn.click();
await addTabBtn.click();
await driver.imageHelper.compareScreen();
await bottomNavigationBasePage.refreshTabItems();
@ -118,7 +118,7 @@ describe(`${suite}-${spec}-suite`, async function () {
await driver.imageHelper.compareScreen();
const goToSecondBtn = await driver.waitForElement("goToSecond");
await goToSecondBtn.tap();
await goToSecondBtn.click();
await driver.imageHelper.compareScreen();
await bottomNavigationBasePage.tabOnItem(1);
@ -157,7 +157,7 @@ describe(`${suite}-${spec}-suite`, async function () {
let selectSecondTabFromCodeBehind = await driver.waitForElement("selectSecondTab");
logInfo(`Click on "select second tab button"`);
await selectSecondTabFromCodeBehind.tap();
await selectSecondTabFromCodeBehind.click();
await driver.imageHelper.compareScreen();
await driver.backgroundApp(1);
@ -168,7 +168,7 @@ describe(`${suite}-${spec}-suite`, async function () {
selectSecondTabFromCodeBehind = await driver.waitForElement("selectSecondTab");
logInfo(`Click on "select second tab button"`);
await selectSecondTabFromCodeBehind.tap();
await selectSecondTabFromCodeBehind.click();
await driver.imageHelper.compareScreen();
await driver.backgroundApp(1);
@ -190,10 +190,21 @@ describe(`${suite}-${spec}-suite`, async function () {
await driver.imageHelper.compareScreen();
await driver.backgroundApp(1);
if (driver.isAndroid) {
driver.imageHelper.resetDefaultOptions();
}
await driver.imageHelper.compareScreen();
// await driver.setOrientation(DeviceOrientation.PORTRAIT);
await driver.imageHelper.compareScreen();
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();
}
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
await bottomNavigationBasePage.navigateBackToSuitMainPage();

View File

@ -3,7 +3,7 @@ import { PageObjectBaseModel } from "../../page-object-base-model";
import { ElementCacheStrategy } from "../../helpers/navigation-helper";
export abstract class TabNavigationBasePage extends PageObjectBaseModel {
protected bottomNavigatioinTabRect: IRectangle;
protected bottomNavigationTabRect: IRectangle;
protected bottomNavigationItems: Array<UIElement>;
protected bottomNavigationItemsRects: Map<number, Point> = new Map();
@ -34,8 +34,8 @@ export abstract class TabNavigationBasePage extends PageObjectBaseModel {
}
async refreshTabWidget() {
const bottomNavigatioinTab = await this.mainWidget();
this.bottomNavigatioinTabRect = await bottomNavigatioinTab.getRectangle();
const bottomNavigationTab = await this.mainWidget();
this.bottomNavigationTabRect = await bottomNavigationTab.getRectangle();
}
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.y = startPoint.y;
} else {
startPoint.x = this._driver.nsCapabilities.device.viewportRect.width - 5;
startPoint.y = this._driver.nsCapabilities.device.viewportRect.y
+ this._driver.nsCapabilities.device.viewportRect.height / 2;
endPoint.x = this._driver.nsCapabilities.device.viewportRect.x + 5;
endPoint.y = startPoint.y;
if (this._driver.nsCapabilities.device.viewportRect) {
startPoint.x = this._driver.nsCapabilities.device.viewportRect.width - 5;
startPoint.y = this._driver.nsCapabilities.device.viewportRect.y
+ this._driver.nsCapabilities.device.viewportRect.height / 2;
endPoint.x = this._driver.nsCapabilities.device.viewportRect.x + 5;
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);

View File

@ -72,12 +72,12 @@ describe(`${suite}-${spec}-suite`, async function () {
await driver.swipe(
{
x: driver.nsCapabilities.device.viewportRect.width + driver.nsCapabilities.device.viewportRect.x - 10,
y: driver.nsCapabilities.device.viewportRect.height / 2
x: driver.imageHelper.options.cropRectangle.width + driver.imageHelper.options.cropRectangle.x - 10,
y: driver.imageHelper.options.cropRectangle.height / 2
},
{
y: 0,
x: driver.nsCapabilities.device.viewportRect.x + 10
x: driver.imageHelper.options.cropRectangle.x + 10
}
, 100);
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");
let btns = await driver.findElementsByClassName(tabItemLocator, 5000);
await btns[index].tap();
await btns[index].click();
await driver.imageHelper.compareScreen();
btns = await driver.findElementsByClassName(tabItemLocator, 5000);
await btns[index - 1].tap();
await btns[index - 1].click();
await driver.imageHelper.compareScreen();
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
@ -235,10 +235,10 @@ describe(`${suite}-${spec}-suite`, async function () {
await tabViewBasePage.navigateToSample("text-transform");
await driver.imageHelper.compareScreen();
await (await driver.waitForElement("apply")).tap();
await (await driver.waitForElement("apply")).click();
await driver.imageHelper.compareScreen();
await (await driver.waitForElement("reset")).tap();
await (await driver.waitForElement("reset")).click();
await driver.imageHelper.compareScreen();
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());

View File

@ -67,19 +67,19 @@ describe(`${suite}-${spec}-suite`, async function () {
}
const scenarioBtn = await driver.waitForElement(sample.sample);
await scenarioBtn.tap();
await scenarioBtn.click();
imageName = setImageName(suite, spec, imageName);
await driver.imageHelper.compareScreen({ imageName: imageName, timeOutSeconds: 5, tolerance: 0, toleranceType: ImageOptions.pixel });
const tabTwo = await driver.waitForElement(sample.tab2);
await tabTwo.click();
await driver.imageHelper.compareScreen({ imageName: imageName, timeOutSeconds: 5 });
const imageComparissonresult = driver.imageHelper.hasImageComparisonPassed();
assert.isTrue(imageComparissonresult);
const imageComparisonResult = driver.imageHelper.hasImageComparisonPassed();
assert.isTrue(imageComparisonResult);
if (imageComparissonresult) {
if (imageComparisonResult) {
const tabOne = await driver.waitForElement(sample.tab1);
await tabOne.tap();
await tabOne.click();
}
});
}

View File

@ -2,6 +2,8 @@ import { nsCapabilities, createDriver, AppiumDriver } from "nativescript-dev-app
import { TabsViewBasePage } from "./tabs-view-base-page";
import { assert } from "chai";
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 spec = "tabs";
@ -81,7 +83,12 @@ describe(`${imagePrefix}-suite`, async function () {
await tabsViewBasePage.tabOnItem(1);
await driver.imageHelper.compareScreen();
await tabsViewBasePage.tabOnItem(2);
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 driver.imageHelper.compareScreen();
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
@ -226,8 +233,8 @@ describe(`${imagePrefix}-suite`, async function () {
// add items
const addTabBtn = await driver.waitForElement("add-tab");
await addTabBtn.tap();
await addTabBtn.tap();
await addTabBtn.click();
await addTabBtn.click();
await driver.imageHelper.compareScreen();
await tabsViewBasePage.refreshTabItems();

View File

@ -1,13 +1,13 @@
import { AppiumDriver } from "nativescript-dev-appium";
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 {
private readonly mainWidgetXPath: string;
private mainWidgetXPath: string;
constructor(_driver: AppiumDriver) {
super(_driver, ["tabs"]);
this.mainWidgetXPath = this._driver.isIOS ?
`//XCUIElementTypeOther[@name="tabNavigation"]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeCollectionView`
: `//android.view.ViewGroup[@content-desc="tabNavigation"]/android.widget.HorizontalScrollView/android.widget.LinearLayout`;
this.loadMainWidgetXpath();
}
async getItems() {
@ -22,4 +22,18 @@ export class TabsViewBasePage extends TabNavigationBasePage {
async mainWidget() {
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!");
}
}
}