| 
									
										
										
										
											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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-07 13:48:30 -07:00
										 |  |  | import type { Page } from './page'; | 
					
						
							| 
									
										
										
										
											2025-02-07 13:54:01 -08:00
										 |  |  | import type * as api from '../../types/types'; | 
					
						
							|  |  |  | import type * as channels from '@protocol/channels'; | 
					
						
							| 
									
										
										
										
											2020-06-25 18:01:18 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-26 17:05:57 -08:00
										 |  |  | export class Keyboard implements api.Keyboard { | 
					
						
							| 
									
										
										
										
											2021-09-07 13:48:30 -07:00
										 |  |  |   private _page: Page; | 
					
						
							| 
									
										
										
										
											2020-06-25 18:01:18 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-07 13:48:30 -07:00
										 |  |  |   constructor(page: Page) { | 
					
						
							|  |  |  |     this._page = page; | 
					
						
							| 
									
										
										
										
											2020-06-25 18:01:18 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   async down(key: string) { | 
					
						
							| 
									
										
										
										
											2021-11-19 16:28:11 -08:00
										 |  |  |     await this._page._channel.keyboardDown({ key }); | 
					
						
							| 
									
										
										
										
											2020-06-25 18:01:18 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   async up(key: string) { | 
					
						
							| 
									
										
										
										
											2021-11-19 16:28:11 -08:00
										 |  |  |     await this._page._channel.keyboardUp({ key }); | 
					
						
							| 
									
										
										
										
											2020-06-25 18:01:18 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   async insertText(text: string) { | 
					
						
							| 
									
										
										
										
											2021-11-19 16:28:11 -08:00
										 |  |  |     await this._page._channel.keyboardInsertText({ text }); | 
					
						
							| 
									
										
										
										
											2020-06-25 18:01:18 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-24 17:05:16 -07:00
										 |  |  |   async type(text: string, options: channels.PageKeyboardTypeOptions = {}) { | 
					
						
							| 
									
										
										
										
											2021-11-19 16:28:11 -08:00
										 |  |  |     await this._page._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 = {}) { | 
					
						
							| 
									
										
										
										
											2021-11-19 16:28:11 -08:00
										 |  |  |     await this._page._channel.keyboardPress({ key, ...options }); | 
					
						
							| 
									
										
										
										
											2020-06-25 18:01:18 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-26 17:05:57 -08:00
										 |  |  | export class Mouse implements api.Mouse { | 
					
						
							| 
									
										
										
										
											2021-09-07 13:48:30 -07:00
										 |  |  |   private _page: Page; | 
					
						
							| 
									
										
										
										
											2020-06-25 18:01:18 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-07 13:48:30 -07:00
										 |  |  |   constructor(page: Page) { | 
					
						
							|  |  |  |     this._page = page; | 
					
						
							| 
									
										
										
										
											2020-06-25 18:01:18 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   async move(x: number, y: number, options: { steps?: number } = {}) { | 
					
						
							| 
									
										
										
										
											2021-11-19 16:28:11 -08:00
										 |  |  |     await this._page._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 = {}) { | 
					
						
							| 
									
										
										
										
											2021-11-19 16:28:11 -08:00
										 |  |  |     await this._page._channel.mouseDown({ ...options }); | 
					
						
							| 
									
										
										
										
											2020-06-25 18:01:18 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-24 17:05:16 -07:00
										 |  |  |   async up(options: channels.PageMouseUpOptions = {}) { | 
					
						
							| 
									
										
										
										
											2021-11-19 16:28:11 -08:00
										 |  |  |     await this._page._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 = {}) { | 
					
						
							| 
									
										
										
										
											2021-11-19 16:28:11 -08:00
										 |  |  |     await this._page._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 }); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-09-14 15:22:52 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   async wheel(deltaX: number, deltaY: number) { | 
					
						
							| 
									
										
										
										
											2021-11-19 16:28:11 -08:00
										 |  |  |     await this._page._channel.mouseWheel({ deltaX, deltaY }); | 
					
						
							| 
									
										
										
										
											2021-09-14 15:22:52 -04:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-06-25 18:01:18 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-10-19 10:07:33 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-26 17:05:57 -08:00
										 |  |  | export class Touchscreen implements api.Touchscreen { | 
					
						
							| 
									
										
										
										
											2021-09-07 13:48:30 -07:00
										 |  |  |   private _page: Page; | 
					
						
							| 
									
										
										
										
											2020-10-19 10:07:33 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-07 13:48:30 -07:00
										 |  |  |   constructor(page: Page) { | 
					
						
							|  |  |  |     this._page = page; | 
					
						
							| 
									
										
										
										
											2020-10-19 10:07:33 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   async tap(x: number, y: number) { | 
					
						
							| 
									
										
										
										
											2021-11-19 16:28:11 -08:00
										 |  |  |     await this._page._channel.touchscreenTap({ x, y }); | 
					
						
							| 
									
										
										
										
											2020-10-19 10:07:33 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | } |