/** * 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'; import { BrowserContextOptions, Page, ChromiumBrowserContext } from './types'; export interface Android extends EventEmitter { setDefaultTimeout(timeout: number): void; devices(): Promise; } export interface AndroidDevice extends EventEmitter { input: AndroidInput; setDefaultTimeout(timeout: number): void; on(event: 'webview', handler: (webView: AndroidWebView) => void): this; waitForEvent(event: string, optionsOrPredicate?: (data: any) => boolean | { timeout?: number, predicate?: (data: any) => boolean }): Promise; serial(): string; model(): string; webViews(): AndroidWebView[]; webView(selector: { pkg: string }, options?: { timeout?: number }): Promise; shell(command: string): Promise; open(command: string): Promise; installApk(file: string | Buffer, options?: { args?: string[] }): Promise; push(file: string | Buffer, path: string, options?: { mode?: number }): Promise; launchBrowser(options?: BrowserContextOptions & { pkg?: string }): Promise; close(): Promise; wait(selector: AndroidSelector, options?: { state?: 'gone' } & { timeout?: number }): Promise; fill(selector: AndroidSelector, text: string, options?: { timeout?: number }): Promise; press(selector: AndroidSelector, key: AndroidKey, options?: { duration?: number } & { timeout?: number }): Promise; tap(selector: AndroidSelector, options?: { duration?: number } & { timeout?: number }): Promise; drag(selector: AndroidSelector, dest: { x: number, y: number }, options?: { speed?: number } & { timeout?: number }): Promise; fling(selector: AndroidSelector, direction: 'down' | 'up' | 'left' | 'right', options?: { speed?: number } & { timeout?: number }): Promise; longTap(selector: AndroidSelector, options?: { timeout?: number }): Promise; pinchClose(selector: AndroidSelector, percent: number, options?: { speed?: number } & { timeout?: number }): Promise; pinchOpen(selector: AndroidSelector, percent: number, options?: { speed?: number } & { timeout?: number }): Promise; scroll(selector: AndroidSelector, direction: 'down' | 'up' | 'left' | 'right', percent: number, options?: { speed?: number } & { timeout?: number }): Promise; swipe(selector: AndroidSelector, direction: 'down' | 'up' | 'left' | 'right', percent: number, options?: { speed?: number } & { timeout?: number }): Promise; info(selector: AndroidSelector): Promise; screenshot(options?: { path?: string }): Promise; } export interface AndroidSocket extends EventEmitter { on(event: 'data', handler: (data: Buffer) => void): this; on(event: 'close', handler: () => void): this; write(data: Buffer): Promise; close(): Promise; } export interface AndroidInput { type(text: string): Promise; press(key: AndroidKey): Promise; tap(point: { x: number, y: number }): Promise; swipe(from: { x: number, y: number }, segments: { x: number, y: number }[], steps: number): Promise; drag(from: { x: number, y: number }, to: { x: number, y: number }, steps: number): Promise; } export interface AndroidWebView extends EventEmitter { on(event: 'close', handler: () => void): this; pid(): number; pkg(): string; page(): Promise; } 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';