From 589bb438bf7b5e3e21d1fa56f79e48fbda5f5271 Mon Sep 17 00:00:00 2001 From: Svetoslav Date: Wed, 14 Aug 2019 04:13:29 +0300 Subject: [PATCH] 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 --- e2e/ui-tests-app/.gitignore | 1 + .../bottom-navigation-base-page.ts | 25 ++++++++++++----- .../bottom-navigation.e2e-spec.ts | 27 +++++++++++++------ .../tab-navigation-base-page.ts | 26 +++++++++++------- .../tab-view-common-tests.e2e-spec.ts | 14 +++++----- .../tab-view-css-properties.e2e-spec.ts | 10 +++---- .../tabs/tabs-tests.e2e-spec.ts | 13 ++++++--- .../tabs/tabs-view-base-page.ts | 24 +++++++++++++---- 8 files changed, 97 insertions(+), 43 deletions(-) diff --git a/e2e/ui-tests-app/.gitignore b/e2e/ui-tests-app/.gitignore index ab763f9f9..144fa45ce 100644 --- a/e2e/ui-tests-app/.gitignore +++ b/e2e/ui-tests-app/.gitignore @@ -35,3 +35,4 @@ typings/ # tests mochawesome-report e2e/resources/images/uitestsapp/* +testapp \ No newline at end of file diff --git a/e2e/ui-tests-app/e2e/suites/tab-navigation/bottom-navigation/bottom-navigation-base-page.ts b/e2e/ui-tests-app/e2e/suites/tab-navigation/bottom-navigation/bottom-navigation-base-page.ts index abe5d944a..09c91fff7 100644 --- a/e2e/ui-tests-app/e2e/suites/tab-navigation/bottom-navigation/bottom-navigation-base-page.ts +++ b/e2e/ui-tests-app/e2e/suites/tab-navigation/bottom-navigation/bottom-navigation-base-page.ts @@ -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 = (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!"); + } + } } \ No newline at end of file diff --git a/e2e/ui-tests-app/e2e/suites/tab-navigation/bottom-navigation/bottom-navigation.e2e-spec.ts b/e2e/ui-tests-app/e2e/suites/tab-navigation/bottom-navigation/bottom-navigation.e2e-spec.ts index d6c537ff0..1b9fbbf0c 100644 --- a/e2e/ui-tests-app/e2e/suites/tab-navigation/bottom-navigation/bottom-navigation.e2e-spec.ts +++ b/e2e/ui-tests-app/e2e/suites/tab-navigation/bottom-navigation/bottom-navigation.e2e-spec.ts @@ -44,7 +44,7 @@ describe(`${suite}-${spec}-suite`, async function () { await bottomNavigationBasePage.tabOnItem(1); await driver.imageHelper.compareScreen(); - + assert.isTrue(driver.imageHelper.hasImageComparisonPassed()); await bottomNavigationBasePage.navigateBackToSuitMainPage(); @@ -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(); diff --git a/e2e/ui-tests-app/e2e/suites/tab-navigation/tab-navigation-base-page.ts b/e2e/ui-tests-app/e2e/suites/tab-navigation/tab-navigation-base-page.ts index 595fb2ebb..68e312637 100644 --- a/e2e/ui-tests-app/e2e/suites/tab-navigation/tab-navigation-base-page.ts +++ b/e2e/ui-tests-app/e2e/suites/tab-navigation/tab-navigation-base-page.ts @@ -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; protected bottomNavigationItemsRects: Map = 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) { @@ -52,18 +52,26 @@ export abstract class TabNavigationBasePage extends PageObjectBaseModel { const endPoint = {}; if (this._driver.isIOS) { - startPoint.x = (this._driver.nsCapabilities.device.viewportRect.x / this._driver.nsCapabilities.device.config.density + startPoint.x = (this._driver.nsCapabilities.device.viewportRect.x / this._driver.nsCapabilities.device.config.density + this._driver.nsCapabilities.device.viewportRect.width / this._driver.nsCapabilities.device.config.density); startPoint.y = this._driver.nsCapabilities.device.viewportRect.y / this._driver.nsCapabilities.device.config.density + (this._driver.nsCapabilities.device.viewportRect.height / this._driver.nsCapabilities.device.config.density) / 2; 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); diff --git a/e2e/ui-tests-app/e2e/suites/tab-navigation/tab-view/tab-view-common-tests.e2e-spec.ts b/e2e/ui-tests-app/e2e/suites/tab-navigation/tab-view/tab-view-common-tests.e2e-spec.ts index 0e742a4fc..38b15aabc 100644 --- a/e2e/ui-tests-app/e2e/suites/tab-navigation/tab-view/tab-view-common-tests.e2e-spec.ts +++ b/e2e/ui-tests-app/e2e/suites/tab-navigation/tab-view/tab-view-common-tests.e2e-spec.ts @@ -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()); diff --git a/e2e/ui-tests-app/e2e/suites/tab-navigation/tab-view/tab-view-css-properties.e2e-spec.ts b/e2e/ui-tests-app/e2e/suites/tab-navigation/tab-view/tab-view-css-properties.e2e-spec.ts index 17518b948..a1960fd43 100644 --- a/e2e/ui-tests-app/e2e/suites/tab-navigation/tab-view/tab-view-css-properties.e2e-spec.ts +++ b/e2e/ui-tests-app/e2e/suites/tab-navigation/tab-view/tab-view-css-properties.e2e-spec.ts @@ -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(); } }); } diff --git a/e2e/ui-tests-app/e2e/suites/tab-navigation/tabs/tabs-tests.e2e-spec.ts b/e2e/ui-tests-app/e2e/suites/tab-navigation/tabs/tabs-tests.e2e-spec.ts index a889586b3..aef21a7c3 100644 --- a/e2e/ui-tests-app/e2e/suites/tab-navigation/tabs/tabs-tests.e2e-spec.ts +++ b/e2e/ui-tests-app/e2e/suites/tab-navigation/tabs/tabs-tests.e2e-spec.ts @@ -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 && (driver.nsCapabilities).automationName === AutomationName.UiAutomator1 + || driver.isAndroid && (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(); diff --git a/e2e/ui-tests-app/e2e/suites/tab-navigation/tabs/tabs-view-base-page.ts b/e2e/ui-tests-app/e2e/suites/tab-navigation/tabs/tabs-view-base-page.ts index 7cd66c8ff..16d342d45 100644 --- a/e2e/ui-tests-app/e2e/suites/tab-navigation/tabs/tabs-view-base-page.ts +++ b/e2e/ui-tests-app/e2e/suites/tab-navigation/tabs/tabs-view-base-page.ts @@ -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() { @@ -15,11 +15,25 @@ export class TabsViewBasePage extends TabNavigationBasePage { if (this._driver.isIOS) { items.shift(); } - + return items; } async mainWidget() { return await this._driver.findElementByXPath(this.mainWidgetXPath); } + + private loadMainWidgetXpath() { + const automationName = (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!"); + } + } } \ No newline at end of file