2020-06-25 18:01:18 -07:00
|
|
|
/**
|
|
|
|
* Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
* Modifications 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.
|
|
|
|
*/
|
|
|
|
|
2020-08-24 17:05:16 -07:00
|
|
|
import * as channels from '../protocol/channels';
|
2020-06-25 18:01:18 -07:00
|
|
|
|
|
|
|
export class Keyboard {
|
2020-08-24 17:05:16 -07:00
|
|
|
private _channel: channels.PageChannel;
|
2020-06-25 18:01:18 -07:00
|
|
|
|
2020-08-24 17:05:16 -07:00
|
|
|
constructor(channel: channels.PageChannel) {
|
2020-06-25 18:01:18 -07:00
|
|
|
this._channel = channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
async down(key: string) {
|
|
|
|
await this._channel.keyboardDown({ key });
|
|
|
|
}
|
|
|
|
|
|
|
|
async up(key: string) {
|
|
|
|
await this._channel.keyboardUp({ key });
|
|
|
|
}
|
|
|
|
|
|
|
|
async insertText(text: string) {
|
|
|
|
await this._channel.keyboardInsertText({ text });
|
|
|
|
}
|
|
|
|
|
2020-08-24 17:05:16 -07:00
|
|
|
async type(text: string, options: channels.PageKeyboardTypeOptions = {}) {
|
2020-07-06 10:04:09 -07:00
|
|
|
await this._channel.keyboardType({ text, ...options });
|
2020-06-25 18:01:18 -07:00
|
|
|
}
|
|
|
|
|
2020-08-24 17:05:16 -07:00
|
|
|
async press(key: string, options: channels.PageKeyboardPressOptions = {}) {
|
2020-07-06 10:04:09 -07:00
|
|
|
await this._channel.keyboardPress({ key, ...options });
|
2020-06-25 18:01:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Mouse {
|
2020-08-24 17:05:16 -07:00
|
|
|
private _channel: channels.PageChannel;
|
2020-06-25 18:01:18 -07:00
|
|
|
|
2020-08-24 17:05:16 -07:00
|
|
|
constructor(channel: channels.PageChannel) {
|
2020-06-25 18:01:18 -07:00
|
|
|
this._channel = channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
async move(x: number, y: number, options: { steps?: number } = {}) {
|
2020-07-06 10:04:09 -07:00
|
|
|
await this._channel.mouseMove({ x, y, ...options });
|
2020-06-25 18:01:18 -07:00
|
|
|
}
|
|
|
|
|
2020-08-24 17:05:16 -07:00
|
|
|
async down(options: channels.PageMouseDownOptions = {}) {
|
2020-07-06 10:04:09 -07:00
|
|
|
await this._channel.mouseDown({ ...options });
|
2020-06-25 18:01:18 -07:00
|
|
|
}
|
|
|
|
|
2020-08-24 17:05:16 -07:00
|
|
|
async up(options: channels.PageMouseUpOptions = {}) {
|
2020-07-06 10:04:09 -07:00
|
|
|
await this._channel.mouseUp(options);
|
2020-06-25 18:01:18 -07:00
|
|
|
}
|
|
|
|
|
2020-08-24 17:05:16 -07:00
|
|
|
async click(x: number, y: number, options: channels.PageMouseClickOptions = {}) {
|
2020-07-06 10:04:09 -07:00
|
|
|
await this._channel.mouseClick({ x, y, ...options });
|
2020-06-25 18:01:18 -07:00
|
|
|
}
|
|
|
|
|
2020-08-24 17:05:16 -07:00
|
|
|
async dblclick(x: number, y: number, options: Omit<channels.PageMouseClickOptions, 'clickCount'> = {}) {
|
2020-06-25 18:01:18 -07:00
|
|
|
await this.click(x, y, { ...options, clickCount: 2 });
|
|
|
|
}
|
|
|
|
}
|