-
Notifications
You must be signed in to change notification settings - Fork 130
/
helper.ts
46 lines (40 loc) · 1.85 KB
/
helper.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { AppiumDriver, SearchOptions, UIElement, Direction } from "nativescript-dev-appium";
import { runType } from "nativescript-dev-appium/lib/parser";
const isAndroid: boolean = runType.includes("android");
export async function navigateBackToHome(driver: AppiumDriver, view?: string) {
let location = view !== undefined ? view : "AutoComplete Angular";
let homeTitle = await driver.findElementByTextIfExists(location, SearchOptions.exact);
while (homeTitle === undefined) {
await driver.navBack();
await driver.wait(1000);
homeTitle = await driver.findElementByTextIfExists(location, SearchOptions.exact);
}
}
export async function navigateBackToView(driver: AppiumDriver, view: string) {
await navigateBackToHome(driver, view);
}
export async function clickBelowElement(element: UIElement, driver: AppiumDriver, yOffset?: number, xOffset?: number) {
const belowDistance = yOffset ? yOffset : 20;
const xDistance = xOffset ? xOffset : 20;
const textfieldRect = await element.getRectangle();
await driver.clickPoint(textfieldRect.x + xDistance, textfieldRect.height + textfieldRect.y + belowDistance)
}
export async function inputRecord(autocompleteField: UIElement, record: string, driver) {
await autocompleteField.sendKeys(record);
await clickBelowElement(autocompleteField, driver);
}
export async function scrollToElement(driver: AppiumDriver, element: string, direction: Direction = Direction.down) {
let listView;
if (isAndroid) {
listView = await driver.findElementByClassName("android.widget.FrameLayout");
}
else {
listView = await driver.findElementByClassName("XCUIElementTypeTable");
}
const listItem = await listView.scrollTo(
direction,
() => driver.findElementByText(element, SearchOptions.exact),
600
);
return listItem;
}