mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
svetoslavtsenov/extend gestures tests (#7870)
This commit is contained in:
8
e2e/ui-tests-app/.vscode/launch.json
vendored
8
e2e/ui-tests-app/.vscode/launch.json
vendored
@@ -27,7 +27,8 @@
|
|||||||
"--colors",
|
"--colors",
|
||||||
"--opts",
|
"--opts",
|
||||||
"../config/mocha.opts",
|
"../config/mocha.opts",
|
||||||
"--grep=bottom-navigation",
|
"--grep",
|
||||||
|
"gestures-events-gestures",
|
||||||
"-a",
|
"-a",
|
||||||
],
|
],
|
||||||
"internalConsoleOptions": "openOnSessionStart",
|
"internalConsoleOptions": "openOnSessionStart",
|
||||||
@@ -45,10 +46,7 @@
|
|||||||
"--opts",
|
"--opts",
|
||||||
"../config/mocha.opts",
|
"../config/mocha.opts",
|
||||||
"--grep=bottom-navigation",
|
"--grep=bottom-navigation",
|
||||||
"android",
|
"android"
|
||||||
"--grep=bottom-navigation",
|
|
||||||
"--port",
|
|
||||||
"8889",
|
|
||||||
],
|
],
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,55 +1,56 @@
|
|||||||
import * as labelModule from "tns-core-modules/ui/label";
|
import {
|
||||||
import * as gestures from "tns-core-modules/ui/gestures";
|
GestureEventData,
|
||||||
import * as button from "tns-core-modules/ui/button";
|
RotationGestureEventData,
|
||||||
import * as pages from "tns-core-modules/ui/page";
|
GestureTypes,
|
||||||
import * as deviceProperties from "tns-core-modules/platform";
|
SwipeGestureEventData,
|
||||||
import * as stackLayoutModule from "tns-core-modules/ui/layouts/stack-layout";
|
PanGestureEventData,
|
||||||
|
PinchGestureEventData,
|
||||||
|
GestureStateTypes
|
||||||
|
} from "tns-core-modules/ui/gestures";
|
||||||
|
import { Button } from "tns-core-modules/ui/button";
|
||||||
|
import { Label } from "tns-core-modules/ui/label";
|
||||||
|
import { Page } from "tns-core-modules/ui/page";
|
||||||
|
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
|
||||||
|
import { screen, isAndroid } from "tns-core-modules/platform";
|
||||||
|
|
||||||
export function createPage() {
|
export function createPage() {
|
||||||
|
const stack = new StackLayout();
|
||||||
var stack = new stackLayoutModule.StackLayout();
|
var stopButton = new Button();
|
||||||
var labelHeight = Math.round(deviceProperties.screen.mainScreen.heightPixels / (7 * deviceProperties.screen.mainScreen.scale));
|
if (isAndroid) {
|
||||||
var stopButton = new button.Button();
|
stopButton.height = 30;
|
||||||
|
stopButton.fontSize = 8;
|
||||||
|
}
|
||||||
stopButton.text = "Stop Detecting Gestures";
|
stopButton.text = "Stop Detecting Gestures";
|
||||||
|
stopButton.automationText = "stopGesturesDetecting";
|
||||||
stack.addChild(stopButton);
|
stack.addChild(stopButton);
|
||||||
|
|
||||||
var tapLabel = new labelModule.Label();
|
const labelHeight = Math.round(screen.mainScreen.heightPixels / (10 * screen.mainScreen.scale));
|
||||||
tapLabel.text = "Tap here";
|
|
||||||
|
const tapLabel = createLabel("Tap here", labelHeight);
|
||||||
stack.addChild(tapLabel);
|
stack.addChild(tapLabel);
|
||||||
|
|
||||||
var doubletapLabel = new labelModule.Label();
|
const doubleTapLabel = createLabel("Double Tap here", labelHeight);
|
||||||
doubletapLabel.text = "Double Tap here";
|
stack.addChild(doubleTapLabel);
|
||||||
stack.addChild(doubletapLabel);
|
|
||||||
|
|
||||||
var longpressLabel = new labelModule.Label();
|
const longPressLabel = createLabel("Long Press here", labelHeight);
|
||||||
longpressLabel.text = "Long Press here";
|
stack.addChild(longPressLabel);
|
||||||
stack.addChild(longpressLabel);
|
|
||||||
|
|
||||||
var swipeLabel = new labelModule.Label();
|
const tapAndDoubleTapLabel = createLabel("Tap or Double Tap", labelHeight, true);
|
||||||
swipeLabel.height = labelHeight;
|
stack.addChild(tapAndDoubleTapLabel);
|
||||||
swipeLabel.text = "Swipe here";
|
|
||||||
swipeLabel.textWrap = true;
|
const swipeLabel = createLabel("Swipe here", labelHeight, true);
|
||||||
stack.addChild(swipeLabel);
|
stack.addChild(swipeLabel);
|
||||||
|
|
||||||
var panLabel = new labelModule.Label();
|
const panLabel = createLabel("Pan here", labelHeight, true);
|
||||||
panLabel.height = labelHeight;
|
|
||||||
panLabel.text = "Pan here";
|
|
||||||
panLabel.textWrap = true;
|
|
||||||
stack.addChild(panLabel);
|
stack.addChild(panLabel);
|
||||||
|
|
||||||
var pinchLabel = new labelModule.Label();
|
const pinchLabel = createLabel("Pinch here", labelHeight, true);
|
||||||
pinchLabel.height = labelHeight;
|
|
||||||
pinchLabel.text = "Pinch here";
|
|
||||||
pinchLabel.textWrap = true;
|
|
||||||
stack.addChild(pinchLabel);
|
stack.addChild(pinchLabel);
|
||||||
|
|
||||||
var rotaionLabel = new labelModule.Label();
|
const rotationLabel = createLabel("Rotate here", labelHeight, true);
|
||||||
rotaionLabel.height = labelHeight;
|
stack.addChild(rotationLabel);
|
||||||
rotaionLabel.text = "Rotate here";
|
|
||||||
rotaionLabel.textWrap = true;
|
|
||||||
stack.addChild(rotaionLabel);
|
|
||||||
|
|
||||||
stopButton.on(button.Button.tapEvent, function () {
|
stopButton.on("tap", function () {
|
||||||
observer1.disconnect();
|
observer1.disconnect();
|
||||||
observer2.disconnect();
|
observer2.disconnect();
|
||||||
observer3.disconnect();
|
observer3.disconnect();
|
||||||
@@ -57,77 +58,111 @@ export function createPage() {
|
|||||||
observer5.disconnect();
|
observer5.disconnect();
|
||||||
observer6.disconnect();
|
observer6.disconnect();
|
||||||
observer7.disconnect();
|
observer7.disconnect();
|
||||||
|
observer8.disconnect();
|
||||||
|
observer9.disconnect();
|
||||||
tapLabel.text = "Gestures detection disabled";
|
tapLabel.text = "Gestures detection disabled";
|
||||||
doubletapLabel.text = "Gestures detection disabled";
|
tapLabel.automationText = "Gestures detection disabled";
|
||||||
longpressLabel.text = "Gestures detection disabled";
|
doubleTapLabel.text = "Gestures detection disabled";
|
||||||
swipeLabel.text = "Gesturesd detection disabled";
|
doubleTapLabel.automationText = "Gestures detection disabled";
|
||||||
|
longPressLabel.text = "Gestures detection disabled";
|
||||||
|
longPressLabel.automationText = "Gestures detection disabled";
|
||||||
|
swipeLabel.text = "Gestures detection disabled";
|
||||||
|
swipeLabel.automationText = "Gestures detection disabled";
|
||||||
panLabel.text = "Gestures detection disabled";
|
panLabel.text = "Gestures detection disabled";
|
||||||
|
panLabel.automationText = "Gestures detection disabled";
|
||||||
pinchLabel.text = "Gestures detection disabled";
|
pinchLabel.text = "Gestures detection disabled";
|
||||||
rotaionLabel.text = "Gestures detection disabled";
|
pinchLabel.automationText = "Gestures detection disabled";
|
||||||
|
rotationLabel.text = "Gestures detection disabled";
|
||||||
|
rotationLabel.automationText = "Gestures detection disabled";
|
||||||
|
tapAndDoubleTapLabel.text = "Gestures detection disabled";
|
||||||
|
tapAndDoubleTapLabel.automationText = "Gestures detection disabled";
|
||||||
});
|
});
|
||||||
|
|
||||||
tapLabel.on(gestures.GestureTypes.tap, function (args: gestures.GestureEventData) {
|
tapLabel.on(GestureTypes[GestureTypes.tap], function (args: GestureEventData) {
|
||||||
tapLabel.text = "Tap gesture detected, " + (args.object === tapLabel);
|
tapLabel.text = "Tap gesture detected, " + (args.object === tapLabel);
|
||||||
});
|
});
|
||||||
|
|
||||||
var observer1 = tapLabel.getGestureObservers(gestures.GestureTypes.tap)[0];
|
const observer1 = tapLabel.getGestureObservers(GestureTypes.tap)[0];
|
||||||
|
|
||||||
doubletapLabel.on(gestures.GestureTypes.doubleTap, function (args: gestures.GestureEventData) {
|
doubleTapLabel.on(GestureTypes[GestureTypes.doubleTap], function (args: GestureEventData) {
|
||||||
doubletapLabel.text = "Double Tap gesture detected, " + (args.object === doubletapLabel);
|
doubleTapLabel.text = "Double Tap gesture detected, " + (args.object === doubleTapLabel);
|
||||||
});
|
});
|
||||||
|
|
||||||
var observer2 = doubletapLabel.getGestureObservers(gestures.GestureTypes.doubleTap)[0];
|
const observer2 = doubleTapLabel.getGestureObservers(GestureTypes.doubleTap)[0];
|
||||||
|
|
||||||
longpressLabel.on(gestures.GestureTypes.longPress, function (args: gestures.GestureEventData) {
|
longPressLabel.on(GestureTypes[GestureTypes.longPress], function (args: GestureEventData) {
|
||||||
longpressLabel.text = "Long Press gesture detected, " + (args.object === longpressLabel);
|
longPressLabel.text = "Long Press gesture detected, " + (args.object === longPressLabel);
|
||||||
});
|
});
|
||||||
|
|
||||||
var observer3 = longpressLabel.getGestureObservers(gestures.GestureTypes.longPress)[0];
|
const observer3 = longPressLabel.getGestureObservers(GestureTypes.longPress)[0];
|
||||||
|
|
||||||
swipeLabel.on(gestures.GestureTypes.swipe, function (args: gestures.SwipeGestureEventData) {
|
swipeLabel.on(GestureTypes[GestureTypes.swipe], function (args: SwipeGestureEventData) {
|
||||||
swipeLabel.text = "Swipe Direction: " + args.direction + ", " + (args.object === swipeLabel); // + getStateAsString(args.state);
|
swipeLabel.text = "Swipe Direction: " + args.direction + ", " + (args.object === swipeLabel); // + getStateAsString(args.state);
|
||||||
});
|
});
|
||||||
|
|
||||||
var observer4 = swipeLabel.getGestureObservers(gestures.GestureTypes.swipe)[0];
|
const observer4 = swipeLabel.getGestureObservers(GestureTypes.swipe)[0];
|
||||||
|
|
||||||
panLabel.on(gestures.GestureTypes.pan, function (args: gestures.PanGestureEventData) {
|
panLabel.on(GestureTypes[GestureTypes.pan], function (args: PanGestureEventData) {
|
||||||
panLabel.text = "Pan deltaX:" + Math.round(args.deltaX) + "; deltaY:" + Math.round(args.deltaY) + ";" + ", " + (args.object === panLabel) + getStateAsString(args.state);
|
panLabel.text = "Pan deltaX:" + Math.round(args.deltaX) + "; deltaY:" + Math.round(args.deltaY) + ";" + ", " + (args.object === panLabel) + getStateAsString(args.state);
|
||||||
});
|
});
|
||||||
|
|
||||||
var observer5 = panLabel.getGestureObservers(gestures.GestureTypes.pan)[0];
|
const observer5 = panLabel.getGestureObservers(GestureTypes.pan)[0];
|
||||||
|
|
||||||
pinchLabel.on(gestures.GestureTypes.pinch, function (args: gestures.PinchGestureEventData) {
|
pinchLabel.on(GestureTypes[GestureTypes.pinch], function (args: PinchGestureEventData) {
|
||||||
pinchLabel.text = "Pinch Scale: " + Math.round(args.scale) + ", " + (args.object === pinchLabel) + getStateAsString(args.state);
|
pinchLabel.text = "Pinch Scale: " + Math.round(args.scale) + ", " + (args.object === pinchLabel) + getStateAsString(args.state);
|
||||||
});
|
});
|
||||||
|
|
||||||
var observer6 = pinchLabel.getGestureObservers(gestures.GestureTypes.pinch)[0];
|
const observer6 = pinchLabel.getGestureObservers(GestureTypes.pinch)[0];
|
||||||
|
|
||||||
rotaionLabel.on(gestures.GestureTypes.rotation, function (args: gestures.RotationGestureEventData) {
|
rotationLabel.on(GestureTypes[GestureTypes.rotation], function (args: RotationGestureEventData) {
|
||||||
rotaionLabel.text = "Rotation: " + Math.round(args.rotation) + ", " + (args.object === rotaionLabel) + getStateAsString(args.state);
|
rotationLabel.text = "Rotation: " + Math.round(args.rotation) + ", " + (args.object === rotationLabel) + getStateAsString(args.state);
|
||||||
});
|
});
|
||||||
|
|
||||||
var observer7 = rotaionLabel.getGestureObservers(gestures.GestureTypes.rotation)[0];
|
const observer7 = rotationLabel.getGestureObservers(GestureTypes.rotation)[0];
|
||||||
|
|
||||||
var page = new pages.Page();
|
tapAndDoubleTapLabel.on(GestureTypes[GestureTypes.doubleTap], function (args: GestureEventData) {
|
||||||
|
tapAndDoubleTapLabel.text = "Last action: Double tap gesture, " + (args.object === tapAndDoubleTapLabel);
|
||||||
|
});
|
||||||
|
|
||||||
|
const observer8 = tapAndDoubleTapLabel.getGestureObservers(GestureTypes.doubleTap)[0];
|
||||||
|
|
||||||
|
tapAndDoubleTapLabel.on(GestureTypes[GestureTypes.tap], function (args: GestureEventData) {
|
||||||
|
tapAndDoubleTapLabel.text = "Last action: Tap gesture, " + (args.object === tapAndDoubleTapLabel);
|
||||||
|
});
|
||||||
|
|
||||||
|
const observer9 = tapAndDoubleTapLabel.getGestureObservers(GestureTypes.tap)[0];
|
||||||
|
|
||||||
|
const page = new Page();
|
||||||
page.content = stack;
|
page.content = stack;
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
var states = new Array<string>();
|
function getStateAsString(state: GestureStateTypes): string {
|
||||||
function getStateAsString(state: gestures.GestureStateTypes): string {
|
const states = new Array<string>();
|
||||||
if (state === gestures.GestureStateTypes.began) {
|
if (state === GestureStateTypes.began) {
|
||||||
states.length = 0;
|
states.length = 0;
|
||||||
states.push("began");
|
states.push("began");
|
||||||
} else if (state === gestures.GestureStateTypes.cancelled) {
|
} else if (state === GestureStateTypes.cancelled) {
|
||||||
states.push("cancelled");
|
states.push("cancelled");
|
||||||
} else if (state === gestures.GestureStateTypes.changed) {
|
} else if (state === GestureStateTypes.changed) {
|
||||||
if (states.indexOf("changed") === -1) {
|
if (states.indexOf("changed") === -1) {
|
||||||
states.push("changed");
|
states.push("changed");
|
||||||
}
|
}
|
||||||
} else if (state === gestures.GestureStateTypes.ended) {
|
} else if (state === GestureStateTypes.ended) {
|
||||||
states.push("ended");
|
states.push("ended");
|
||||||
}
|
}
|
||||||
|
|
||||||
return ", states: " + states.join(",");
|
return ", states: " + states.join(",");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createLabel(text: string, labelHeight: number, shouldWrap = false) {
|
||||||
|
const label = new Label();
|
||||||
|
label.height = labelHeight;
|
||||||
|
label.text = text;
|
||||||
|
label.textWrap = shouldWrap;
|
||||||
|
label.borderColor = "green";
|
||||||
|
label.borderWidth = 1;
|
||||||
|
|
||||||
|
return label;
|
||||||
|
}
|
||||||
@@ -1,16 +1,27 @@
|
|||||||
import * as observable from "tns-core-modules/data/observable";
|
import { EventData } from "tns-core-modules/data/observable";
|
||||||
import * as gestures from "tns-core-modules/ui/gestures";
|
import { GestureEventData } from "tns-core-modules/ui/gestures";
|
||||||
import * as pages from "tns-core-modules/ui/page";
|
import { Page } from "tns-core-modules/ui/page";
|
||||||
|
import { Label } from "tns-core-modules/ui/label/label";
|
||||||
|
|
||||||
export function pageLoaded(args: observable.EventData) {
|
export function pageLoaded(args: EventData) {
|
||||||
var page = <pages.Page>args.object;
|
var page = <Page>args.object;
|
||||||
page.bindingContext = { tapAction: tapAction, doubleTapAction: doubleTapAction };
|
page.bindingContext = { tapAction: tapAction, doubleTapAction: doubleTapAction, cleanResult: cleanResult };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function tapAction(args: gestures.GestureEventData) {
|
export function tapAction(args: GestureEventData) {
|
||||||
console.log("tapAction");
|
setResult(args, "tapAction");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doubleTapAction(args: gestures.GestureEventData) {
|
export function doubleTapAction(args: GestureEventData) {
|
||||||
console.log("doubleTapAction");
|
setResult(args, "doubleTapAction");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function cleanResult(args: GestureEventData) {
|
||||||
|
setResult(args, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
const setResult = (args: GestureEventData, text: string) => {
|
||||||
|
console.log(text);
|
||||||
|
const resultPanel: Label = (<Page>((<any>args.object).page)).getViewById("resultContainer");
|
||||||
|
resultPanel.text = text;
|
||||||
|
};
|
||||||
|
|||||||
@@ -2,5 +2,8 @@
|
|||||||
<StackLayout>
|
<StackLayout>
|
||||||
<Label text="Handlers as exports" tap="tapAction" doubleTap="doubleTapAction" />
|
<Label text="Handlers as exports" tap="tapAction" doubleTap="doubleTapAction" />
|
||||||
<Label text="Bound handlers" tap="{{ tapAction }}" doubleTap="{{ doubleTapAction }}" />
|
<Label text="Bound handlers" tap="{{ tapAction }}" doubleTap="{{ doubleTapAction }}" />
|
||||||
|
<Label text="Result: "></Label>
|
||||||
|
<Label id="resultContainer"></Label>
|
||||||
|
<Button text="clean-result" tap="{{ cleanResult }}" />
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</Page>
|
</Page>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export class StylesPage extends PageObjectBaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async tapAppBtn() {
|
async tapAppBtn() {
|
||||||
await (await this.btnApp()).tap();
|
await (await this.btnApp()).click();
|
||||||
logInfo(`Tap on '${this.app}' button.`);
|
logInfo(`Tap on '${this.app}' button.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import { AppiumDriver, createDriver, nsCapabilities, SearchOptions, Direction, LogType } from "nativescript-dev-appium";
|
||||||
|
import { GesturesPage } from "../gestures/gestures-page";
|
||||||
|
import { assert } from "chai";
|
||||||
|
import { setImageName } from "../../../helpers/image-helper";
|
||||||
|
import { EventsGesturesBasePage } from "../events-gestures-base-page";
|
||||||
|
|
||||||
|
const suite = "gestures-events";
|
||||||
|
const spec = "common";
|
||||||
|
const imagePrefix = `${suite}-${spec}`;
|
||||||
|
|
||||||
|
describe(`${imagePrefix}-suite`, () => {
|
||||||
|
let driver: AppiumDriver;
|
||||||
|
let basePage: EventsGesturesBasePage;
|
||||||
|
|
||||||
|
before(async function () {
|
||||||
|
nsCapabilities.testReporter.context = this;
|
||||||
|
driver = await createDriver();
|
||||||
|
await driver.restartApp();
|
||||||
|
basePage = new EventsGesturesBasePage(driver);
|
||||||
|
await basePage.initSuite();
|
||||||
|
});
|
||||||
|
|
||||||
|
after(async function () {
|
||||||
|
await basePage.endSuite();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
driver.imageHelper.testName = setImageName(suite, spec, this.currentTest.title);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async function () {
|
||||||
|
if (this.currentTest.state === "failed") {
|
||||||
|
await driver.logTestArtifacts(this.currentTest.title);
|
||||||
|
await driver.restartApp();
|
||||||
|
await basePage.initSuite();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`${imagePrefix}-handlers`, async function () {
|
||||||
|
const getResult = async (text) => {
|
||||||
|
return (await driver.waitForElement(text));
|
||||||
|
};
|
||||||
|
|
||||||
|
const cleanResult = async () => {
|
||||||
|
return await (await driver.waitForElement("clean-result")).click();
|
||||||
|
};
|
||||||
|
|
||||||
|
basePage.navigateToSample("handlers");
|
||||||
|
|
||||||
|
const handlersExport = await driver.findElementByText("Handlers as exports");
|
||||||
|
|
||||||
|
await handlersExport.click();
|
||||||
|
assert.isTrue(getResult("tapAction") != null);
|
||||||
|
await cleanResult();
|
||||||
|
|
||||||
|
await handlersExport.doubleTap();
|
||||||
|
assert.isTrue(getResult("doubleTapAction") != null);
|
||||||
|
await cleanResult();
|
||||||
|
|
||||||
|
const boundHandlers = await driver.findElementByText("Bound handlers");
|
||||||
|
await boundHandlers.click();
|
||||||
|
assert.isTrue(getResult("tapAction") != null);
|
||||||
|
await cleanResult();
|
||||||
|
await handlersExport.doubleTap();
|
||||||
|
assert.isTrue(getResult("doubleTapAction") != null);
|
||||||
|
await cleanResult();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { AppiumDriver } from "nativescript-dev-appium";
|
||||||
|
import { PageObjectBaseModel } from "../../page-object-base-model";
|
||||||
|
import { ElementCacheStrategy } from "../../helpers/navigation-helper";
|
||||||
|
|
||||||
|
export class EventsGesturesBasePage extends PageObjectBaseModel {
|
||||||
|
|
||||||
|
constructor(_driver: AppiumDriver, navigationLinks?: Array<string>) {
|
||||||
|
super(_driver, navigationLinks ? navigationLinks.unshift("events") && navigationLinks : ["events"], ElementCacheStrategy.none);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { AppiumDriver } from "nativescript-dev-appium";
|
||||||
|
import { EventsGesturesBasePage } from "../events-gestures-base-page";
|
||||||
|
|
||||||
|
export class GesturesPage extends EventsGesturesBasePage {
|
||||||
|
|
||||||
|
constructor(_driver: AppiumDriver) {
|
||||||
|
super(_driver, ["gestures"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async btnStopDetection() {
|
||||||
|
return this._driver.waitForElement("stopGesturesDetecting");
|
||||||
|
}
|
||||||
|
|
||||||
|
async stopDetection() {
|
||||||
|
return await (await this.btnStopDetection()).click();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
import { AppiumDriver, createDriver, nsCapabilities, SearchOptions, Direction } from "nativescript-dev-appium";
|
||||||
|
import { GesturesPage } from "./gestures-page";
|
||||||
|
import { assert } from "chai";
|
||||||
|
import { setImageName } from "../../../helpers/image-helper";
|
||||||
|
|
||||||
|
const suite = "gestures-events";
|
||||||
|
const spec = "gestures";
|
||||||
|
const imagePrefix = `${suite}-${spec}`;
|
||||||
|
|
||||||
|
describe(`${imagePrefix}-suite`, () => {
|
||||||
|
let driver: AppiumDriver;
|
||||||
|
let gesturesPage: GesturesPage;
|
||||||
|
|
||||||
|
before(async function () {
|
||||||
|
nsCapabilities.testReporter.context = this;
|
||||||
|
driver = await createDriver();
|
||||||
|
await driver.restartApp();
|
||||||
|
gesturesPage = new GesturesPage(driver);
|
||||||
|
await gesturesPage.initSuite();
|
||||||
|
});
|
||||||
|
|
||||||
|
after(async function () {
|
||||||
|
await gesturesPage.endSuite();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
driver.imageHelper.testName = setImageName(suite, spec, this.currentTest.title);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async function () {
|
||||||
|
if (this.currentTest.state === "failed") {
|
||||||
|
await driver.logTestArtifacts(this.currentTest.title);
|
||||||
|
await driver.restartApp();
|
||||||
|
await gesturesPage.initSuite();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("gestures_01_tap", async function () {
|
||||||
|
const lblTap = await driver.waitForElement("Tap here");
|
||||||
|
await lblTap.click();
|
||||||
|
const result = await driver.findElementByTextIfExists("Tap gesture detected, true", SearchOptions.contains);
|
||||||
|
assert.isTrue(result != null && result !== undefined, `Gestures event 'tap' not detected!`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("gestures_02_doubleTap", async function () {
|
||||||
|
const lblDoubleTap = await driver.waitForElement("Double Tap here");
|
||||||
|
await lblDoubleTap.doubleTap();
|
||||||
|
const result = await driver.findElementByTextIfExists("Double Tap gesture detected, true", SearchOptions.contains);
|
||||||
|
assert.isTrue(result != null && result !== undefined, `Gestures event 'Double Tap gesture detected, true' not detected!`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("gestures_03_longPress", async function () {
|
||||||
|
const lblLongPress = await driver.waitForElement("Long Press here");
|
||||||
|
await lblLongPress.hold(5000);
|
||||||
|
const result = await driver.findElementByTextIfExists("Long Press gesture detected, true", SearchOptions.contains);
|
||||||
|
assert.isTrue(result != null && result !== undefined, `Gestures event 'Long Press gesture detected, true' not detected!`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("gestures_longPress", async function () {
|
||||||
|
const lblTapOrDoubleTap = await driver.waitForElement("Tap or Double Tap");
|
||||||
|
const rect = await lblTapOrDoubleTap.getRectangle();
|
||||||
|
await lblTapOrDoubleTap.doubleTap();
|
||||||
|
let result = await driver.findElementByTextIfExists("Last action: Double tap gesture, true", SearchOptions.contains);
|
||||||
|
assert.isTrue(result != null && result !== undefined, `Gestures event 'Last action: Double tap gesture, true' not detected!`);
|
||||||
|
await driver.clickPoint(rect.x, rect.y);
|
||||||
|
result = await driver.findElementByTextIfExists("Last action: Tap gesture, true", SearchOptions.contains);
|
||||||
|
assert.isTrue(result != null && result !== undefined, `Gestures event 'Last action: Tap gesture, true' not detected!`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("gestures_04_swipe", async function () {
|
||||||
|
const lblSwipe = await driver.waitForElement("Swipe here");
|
||||||
|
await lblSwipe.swipe(Direction.left);
|
||||||
|
const result = await driver.findElementByTextIfExists("Swipe Direction: 1, true", SearchOptions.contains);
|
||||||
|
assert.isTrue(result != null && result !== undefined, `Gestures event 'Swipe Direction: 1, true' not detected!`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("gestures_05_pan", async function () {
|
||||||
|
const lblSwipe = await driver.waitForElement("Pan here");
|
||||||
|
const rect = await lblSwipe.getRectangle();
|
||||||
|
await lblSwipe.pan([
|
||||||
|
{ x: rect.x + 100, y: rect.y + 100 },
|
||||||
|
{ x: rect.x + 140, y: rect.y + 120 },
|
||||||
|
{ x: rect.x + 160, y: rect.y + 120 }
|
||||||
|
], { x: 50, y: 50 });
|
||||||
|
|
||||||
|
const result = await driver.findElementByTextIfExists("Pan deltaX", SearchOptions.contains);
|
||||||
|
const text = await result.text();
|
||||||
|
assert.isTrue(/Pan deltaX:\d+; deltaY:\d+;, true, states: ended/.test(text), `Gestures event 'Pan deltaX: ...' not detected!`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("gestures_06_pinch", async function () {
|
||||||
|
const lblPan = await driver.waitForElement("Pinch here");
|
||||||
|
await lblPan.pinch("out");
|
||||||
|
const result = await driver.findElementByTextIfExists("Pinch Scale: 1, true, states: ended", SearchOptions.contains);
|
||||||
|
assert.isTrue(result != null && result !== undefined, `Gestures event '"Pinch Scale: 0, true, states: ended"' not detected!`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("gestures_07_rotate", async function () {
|
||||||
|
const lblPan = await driver.waitForElement("Rotate here");
|
||||||
|
await lblPan.rotate();
|
||||||
|
const result = await driver.findElementByTextIfExists("Rotation: ", SearchOptions.contains);
|
||||||
|
const text = await result.text();
|
||||||
|
assert.isTrue(/Rotation: [a-z0-9 .,+-]\d+, true, states: ended/ig.test(text), `Gestures event 'rotate' not detected!`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("gestures_08_disconnectObserver", async function () {
|
||||||
|
await gesturesPage.navigateBackToSuitMainPage();
|
||||||
|
await gesturesPage.navigateToSample("gestures");
|
||||||
|
const lblTap = await driver.waitForElement("Tap here");
|
||||||
|
const rect = await lblTap.getRectangle();
|
||||||
|
|
||||||
|
await gesturesPage.stopDetection();
|
||||||
|
const result = await driver.findElementByTextIfExists("Gestures detection disabled", SearchOptions.contains);
|
||||||
|
assert.isTrue(result != null && result !== undefined, `Gestures detection is not disabled!`);
|
||||||
|
|
||||||
|
await driver.clickPoint(rect.x, rect.y);
|
||||||
|
const lblTapResult = await driver.findElementByTextIfExists("Tap gesture detected, true", SearchOptions.contains);
|
||||||
|
assert.isTrue(lblTapResult === null || lblTapResult === undefined, `Gestures event 'Tap gesture detected, true' detected but shouldn't since observables are disables!`);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -297,7 +297,7 @@ describe(`${suite}-${spec}-suite`, async function () {
|
|||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
|
|
||||||
const secondTab = await driver.waitForElement("second-tab");
|
const secondTab = await driver.waitForElement("second-tab");
|
||||||
await secondTab.tap();
|
await secondTab.click();
|
||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
|
|
||||||
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
|
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
|
||||||
|
|||||||
@@ -59,14 +59,13 @@ describe(`${suite}-${spec}-suite`, async function () {
|
|||||||
if (driver.isIOS && imageName.includes("android")) {
|
if (driver.isIOS && imageName.includes("android")) {
|
||||||
this.skip();
|
this.skip();
|
||||||
}
|
}
|
||||||
if (driver.platformName === Platform.ANDROID
|
|
||||||
&& (sample.sample.toLowerCase() === "all" || sample.sample.toLowerCase() === "reset")) {
|
|
||||||
await driver.scroll(Direction.down, 400, 200, 300, 200);
|
|
||||||
await driver.scroll(Direction.down, 400, 200, 300, 200);
|
|
||||||
await driver.scroll(Direction.down, 400, 200, 300, 200);
|
|
||||||
|
|
||||||
|
let scenarioBtn = await driver.waitForElement(sample.sample);
|
||||||
|
if (!scenarioBtn) {
|
||||||
|
await driver.scroll(Direction.up, 400, 200, 300, 200);
|
||||||
|
scenarioBtn = await driver.waitForElement(sample.sample);
|
||||||
}
|
}
|
||||||
const scenarioBtn = await driver.waitForElement(sample.sample);
|
|
||||||
await scenarioBtn.click();
|
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 });
|
||||||
|
|||||||
@@ -277,7 +277,7 @@ describe(`${imagePrefix}-suite`, async function () {
|
|||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
|
|
||||||
const secondTab = await driver.waitForElement("second-tab");
|
const secondTab = await driver.waitForElement("second-tab");
|
||||||
await secondTab.tap();
|
await secondTab.click();
|
||||||
await driver.imageHelper.compareScreen();
|
await driver.imageHelper.compareScreen();
|
||||||
|
|
||||||
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
|
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
|
||||||
|
|||||||
Reference in New Issue
Block a user