mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-15 14:11:50 +03:00
144 lines
5.0 KiB
TypeScript
144 lines
5.0 KiB
TypeScript
/**
|
|
* Copyright (c) Microsoft Corporation.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
import { EventEmitter } from 'events';
|
|
|
|
export interface AndroidDevice<BrowserContextOptions, BrowserContext, Page> extends EventEmitter {
|
|
input: AndroidInput;
|
|
|
|
setDefaultTimeout(timeout: number): void;
|
|
on(event: 'webview', handler: (webView: AndroidWebView<Page>) => void): this;
|
|
waitForEvent(event: string, predicate?: (data: any) => boolean): Promise<any>;
|
|
|
|
serial(): string;
|
|
model(): string;
|
|
webViews(): AndroidWebView<Page>[];
|
|
shell(command: string): Promise<string>;
|
|
launchBrowser(options?: BrowserContextOptions & { packageName?: string }): Promise<BrowserContext>;
|
|
close(): Promise<void>;
|
|
|
|
wait(selector: AndroidSelector, options?: { state?: 'gone' } & { timeout?: number }): Promise<void>;
|
|
fill(selector: AndroidSelector, text: string, options?: { timeout?: number }): Promise<void>;
|
|
press(selector: AndroidSelector, key: AndroidKey, options?: { duration?: number } & { timeout?: number }): Promise<void>;
|
|
tap(selector: AndroidSelector, options?: { duration?: number } & { timeout?: number }): Promise<void>;
|
|
drag(selector: AndroidSelector, dest: { x: number, y: number }, options?: { speed?: number } & { timeout?: number }): Promise<void>;
|
|
fling(selector: AndroidSelector, direction: 'down' | 'up' | 'left' | 'right', options?: { speed?: number } & { timeout?: number }): Promise<void>;
|
|
longTap(selector: AndroidSelector, options?: { timeout?: number }): Promise<void>;
|
|
pinchClose(selector: AndroidSelector, percent: number, options?: { speed?: number } & { timeout?: number }): Promise<void>;
|
|
pinchOpen(selector: AndroidSelector, percent: number, options?: { speed?: number } & { timeout?: number }): Promise<void>;
|
|
scroll(selector: AndroidSelector, direction: 'down' | 'up' | 'left' | 'right', percent: number, options?: { speed?: number } & { timeout?: number }): Promise<void>;
|
|
swipe(selector: AndroidSelector, direction: 'down' | 'up' | 'left' | 'right', percent: number, options?: { speed?: number } & { timeout?: number }): Promise<void>;
|
|
|
|
info(selector: AndroidSelector): Promise<AndroidElementInfo>;
|
|
}
|
|
|
|
export interface AndroidInput {
|
|
type(text: string): Promise<void>;
|
|
press(key: AndroidKey): Promise<void>;
|
|
tap(point: { x: number, y: number }): Promise<void>;
|
|
swipe(from: { x: number, y: number }, segments: { x: number, y: number }[], steps: number): Promise<void>;
|
|
drag(from: { x: number, y: number }, to: { x: number, y: number }, steps: number): Promise<void>;
|
|
}
|
|
|
|
export interface AndroidWebView<Page> extends EventEmitter {
|
|
on(event: 'close', handler: () => void): this;
|
|
pid(): number;
|
|
pkg(): string;
|
|
page(): Promise<Page>;
|
|
}
|
|
|
|
export type AndroidElementInfo = {
|
|
clazz: string;
|
|
desc: string;
|
|
res: string;
|
|
pkg: string;
|
|
text: string;
|
|
bounds: { x: number, y: number, width: number, height: number };
|
|
checkable: boolean;
|
|
checked: boolean;
|
|
clickable: boolean;
|
|
enabled: boolean;
|
|
focusable: boolean;
|
|
focused: boolean;
|
|
longClickable: boolean;
|
|
scrollable: boolean;
|
|
selected: boolean;
|
|
};
|
|
|
|
export type AndroidSelector = {
|
|
checkable?: boolean,
|
|
checked?: boolean,
|
|
clazz?: string | RegExp,
|
|
clickable?: boolean,
|
|
depth?: number,
|
|
desc?: string | RegExp,
|
|
enabled?: boolean,
|
|
focusable?: boolean,
|
|
focused?: boolean,
|
|
hasChild?: { selector: AndroidSelector },
|
|
hasDescendant?: { selector: AndroidSelector, maxDepth?: number },
|
|
longClickable?: boolean,
|
|
pkg?: string | RegExp,
|
|
res?: string | RegExp,
|
|
scrollable?: boolean,
|
|
selected?: boolean,
|
|
text?: string | RegExp,
|
|
};
|
|
|
|
export type AndroidKey =
|
|
'Unknown' |
|
|
'SoftLeft' | 'SoftRight' |
|
|
'Home' |
|
|
'Back' |
|
|
'Call' | 'EndCall' |
|
|
'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' |
|
|
'Star' | 'Pound' | '*' | '#' |
|
|
'DialUp' | 'DialDown' | 'DialLeft' | 'DialRight' | 'DialCenter' |
|
|
'VolumeUp' | 'VolumeDown' |
|
|
'Power' |
|
|
'Camera' |
|
|
'Clear' |
|
|
'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' |
|
|
'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z' |
|
|
'Comma' | ',' |
|
|
'Period' | '.' |
|
|
'AltLeft' | 'AltRight' |
|
|
'ShiftLeft' | 'ShiftRight' |
|
|
'Tab' | '\t' |
|
|
'Space' | ' ' |
|
|
'Sym' |
|
|
'Explorer' |
|
|
'Envelop' |
|
|
'Enter' | '\n' |
|
|
'Del' |
|
|
'Grave' |
|
|
'Minus' | '-' |
|
|
'Equals' | '=' |
|
|
'LeftBracket' | '(' |
|
|
'RightBracket' | ')' |
|
|
'Backslash' | '\\' |
|
|
'Semicolon' | ';' |
|
|
'Apostrophe' | '`' |
|
|
'Slash' | '/' |
|
|
'At' |
|
|
'Num' |
|
|
'HeadsetHook' |
|
|
'Focus' |
|
|
'Plus' | '+' |
|
|
'Menu' |
|
|
'Notification' |
|
|
'Search';
|