multi-automator
Version:
Multi terminal automation
142 lines (141 loc) • 3.54 kB
TypeScript
/// <reference types="node" />
import { Viewport } from 'puppeteer-core';
import ElementHandle from './Element';
export interface LaunchOptions {
headless?: boolean;
devtools?: boolean;
defaultViewport?: null | Viewport;
args?: string[];
ignoreDefaultArgs?: boolean | string[];
}
/**
* web 操控类
*/
export default class WebHandler {
/**
* 初始化参数
*/
launchOptions: object;
/**
* 是否开启设备模拟
*/
emulate: boolean;
/**
* 设备
*/
model: string;
/**
* 浏览器路径
*/
browserPath: string;
/**
* browser 实例
*/
browser: any;
/**
* page 实例
*/
page: any;
/**
* 屏幕尺寸
*/
screenSize: object | null;
/**
* Web Operator
*
* @param {string} browserPath 浏览器地址,默认使用 chromium 地址
*/
constructor(browserPath: string);
/**
* init 参数处理
*
* @param launchOptions LaunchOptions
*/
checkInitOptions(launchOptions?: LaunchOptions): void;
/**
* init Web operator
*
* @param {boolean} headless 是否采用无头方案
* @param {boolean} devtools 是否启用调试工具
* @param {array{object}} cookies 需要设置的 cookies
* @param {string} emulate 是否开启设备模拟
* @param {object} headers headers
*/
init(launchOptions?: LaunchOptions, cookies?: object[], emulate?: boolean, headers?: object): Promise<void>;
/**
* 通过 xpath 获取元素操作对象列表
*
* @param {string} expression XPath表达式
* @returns {Promise<Array<ElementHandle>>}
*/
$x(expression: string): Promise<ElementHandle[]>;
/**
* 通过 CSS 选择器获取元素操作对象
*
* @param selector CSS 选择器
* @returns {Promise<ElementHandle|null>}
*/
$(selector: string): Promise<ElementHandle | null>;
/**
* 通过 CSS 选择器获取元素操作对象列表
*
* @param selector CSS 选择器
* @returns {Promise<Array<ElementHandle>>}
*/
$$(selector: string): Promise<ElementHandle[]>;
/**
* 屏幕点击
*
* @param {number} x 横坐标
* @param {number} y 纵坐标
* @return <Promise>
*/
tap(x: number, y: number): Promise<any>;
/**
* 页面滑动
*
* @param {number} fx 起点横坐标
* @param {number} fy 起点纵坐标
* @param {number} tx 终点横坐标
* @param {number} ty 终点纵坐标
*/
swipe(fx: number, fy: number, tx: number, ty: number): Promise<void>;
/**
* 跳转 HTTP 地址
*
* @param {string} path url 路径
* @returns {string}
*/
goto(path?: string): Promise<string>;
/**
* 获取页面宽高
*
* @return {object} screenSize
* @return {number} screenSize.width 宽度,单位是像素
* @return {number} screenSize.height 高度,单位是像素
*/
getScreenSize(): Promise<object>;
/**
* 截图
*
* @param {string} path 图片路径
* @returns {Promise{Buffer|String}}
*/
screenshot(path: string): Promise<Buffer | string>;
/**
* 页面 dom 树
*
* @return <Promise{string}>
*/
source(): Promise<string>;
/**
* browser version
*
* @returns {string} 浏览器版本号
*/
version(): Promise<string>;
/**
* 关闭设备
*/
close(): Promise<void>;
}