UNPKG

9.57 kBTypeScriptView Raw
1import { WebDriver, WebElement } from "../";
2import { Executor } from "./command";
3
4/**
5 * Defines the reference point from which to compute offsets for
6 * {@linkplain ./input.Pointer#move pointer move} actions.
7 */
8export enum Origin {
9 /** Compute offsets relative to the pointer's current position. */
10 POINTER = "pointer",
11 /** Compute offsets relative to the viewport. */
12 VIEWPORT = "viewport",
13}
14
15/**
16 * Enumeration of the buttons used in the advanced interactions API.
17 */
18export enum Button {
19 LEFT = 0,
20 MIDDLE = 1,
21 RIGHT = 2,
22}
23
24export interface IKey {
25 NULL: string;
26 CANCEL: string; // ^break
27 HELP: string;
28 BACK_SPACE: string;
29 TAB: string;
30 CLEAR: string;
31 RETURN: string;
32 ENTER: string;
33 SHIFT: string;
34 CONTROL: string;
35 ALT: string;
36 PAUSE: string;
37 ESCAPE: string;
38 SPACE: string;
39 PAGE_UP: string;
40 PAGE_DOWN: string;
41 END: string;
42 HOME: string;
43 ARROW_LEFT: string;
44 LEFT: string;
45 ARROW_UP: string;
46 UP: string;
47 ARROW_RIGHT: string;
48 RIGHT: string;
49 ARROW_DOWN: string;
50 DOWN: string;
51 INSERT: string;
52 DELETE: string;
53 SEMICOLON: string;
54 EQUALS: string;
55
56 NUMPAD0: string; // number pad keys
57 NUMPAD1: string;
58 NUMPAD2: string;
59 NUMPAD3: string;
60 NUMPAD4: string;
61 NUMPAD5: string;
62 NUMPAD6: string;
63 NUMPAD7: string;
64 NUMPAD8: string;
65 NUMPAD9: string;
66 MULTIPLY: string;
67 ADD: string;
68 SEPARATOR: string;
69 SUBTRACT: string;
70 DECIMAL: string;
71 DIVIDE: string;
72
73 F1: string; // function keys
74 F2: string;
75 F3: string;
76 F4: string;
77 F5: string;
78 F6: string;
79 F7: string;
80 F8: string;
81 F9: string;
82 F10: string;
83 F11: string;
84 F12: string;
85
86 COMMAND: string; // Apple command key
87 META: string; // alias for Windows key
88
89 /**
90 * Simulate pressing many keys at once in a 'chord'. Takes a sequence of
91 * keys or strings, appends each of the values to a string,
92 * and adds the chord termination key ({@link Key.NULL}) and returns
93 * the resulting string.
94 *
95 * Note: when the low-level webdriver key handlers see Keys.NULL, active
96 * modifier keys (CTRL/ALT/SHIFT/etc) release via a keyup event.
97 *
98 * @param {...string} var_args The key sequence to concatenate.
99 * @return {string} The null-terminated key sequence.
100 */
101 chord(...var_args: Array<string | IKey>): string;
102}
103
104/**
105 * Representations of pressable keys that aren't text. These are stored in
106 * the Unicode PUA (Private Use Area) code points, 0xE000-0xF8FF. Refer to
107 * http://www.google.com.au/search?&q=unicode+pua&btnG=Search
108 */
109export const Key: IKey;
110
111export interface IDirection {
112 x?: number | undefined;
113 y?: number | undefined;
114 duration?: number | undefined;
115 origin?: Origin | WebElement | undefined;
116}
117
118export const INTERNAL_COMPUTE_OFFSET_SCRIPT: string;
119
120/**
121 * Used with {@link ./webelement.WebElement#sendKeys WebElement#sendKeys} on
122 * file input elements (`<input type="file">`) to detect when the entered key
123 * sequence defines the path to a file.
124 *
125 * By default, {@linkplain ./webelement.WebElement WebElement's} will enter all
126 * key sequences exactly as entered. You may set a
127 * {@linkplain ./webdriver.WebDriver#setFileDetector file detector} on the
128 * parent WebDriver instance to define custom behavior for handling file
129 * elements. Of particular note is the
130 * {@link selenium-webdriver/remote.FileDetector}, which should be used when
131 * running against a remote
132 * [Selenium Server](https://selenium.dev/downloads/).
133 */
134export class FileDetector {
135 /**
136 * Handles the file specified by the given path, preparing it for use with
137 * the current browser. If the path does not refer to a valid file, it will
138 * be returned unchanged, otherwise a path suitable for use with the current
139 * browser will be returned.
140 *
141 * This default implementation is a no-op. Subtypes may override this function
142 * for custom tailored file handling.
143 *
144 * @param {!./webdriver.WebDriver} driver The driver for the current browser.
145 * @param {string} path The path to process.
146 * @return {!Promise<string>} A promise for the processed file path.
147 * @package
148 */
149 handleFile(driver: WebDriver, path: string): Promise<string>;
150}
151
152export class Device {
153 constructor(type: string, id: string);
154}
155
156export class Pointer extends Device {}
157export class Keyboard extends Device {}
158
159/**
160 * Class for defining sequences of complex user interactions. Each sequence
161 * will not be executed until {@link #perform} is called.
162 *
163 * Example:
164 *
165 * new Actions(driver).
166 * keyDown(Key.SHIFT).
167 * click(element1).
168 * click(element2).
169 * dragAndDrop(element3, element4).
170 * keyUp(Key.SHIFT).
171 * perform();
172 */
173export class Actions {
174 // region Constructors
175
176 constructor(
177 executor: Executor,
178 options?: { async: boolean; bridge: boolean } | { async: boolean } | { bridge: boolean },
179 );
180
181 // endregion
182
183 // region Methods
184 keyboard(): Keyboard;
185 mouse(): Pointer;
186 /**
187 * Executes this action sequence.
188 * @return {!Promise} A promise that will be resolved once
189 * this sequence has completed.
190 */
191 clear(): Promise<void>;
192
193 /**
194 * Executes this action sequence.
195 * @return {!Promise} A promise that will be resolved once
196 * this sequence has completed.
197 */
198 perform(): Promise<void>;
199
200 pause(duration?: number | Device, ...devices: Device[]): Actions;
201
202 /**
203 * Inserts an action to press a mouse button at the mouse's current location.
204 * Defaults to `LEFT`.
205 */
206 press(button?: Button): Actions;
207
208 /**
209 * Inserts an action to release a mouse button at the mouse's current
210 * location. Defaults to `LEFT`.
211 */
212 release(button?: Button): Actions;
213
214 /**
215 * Inserts an action for moving the mouse `x` and `y` pixels relative to the
216 * specified `origin`. The `origin` may be defined as the mouse's
217 * {@linkplain ./input.Origin.POINTER current position}, the
218 * {@linkplain ./input.Origin.VIEWPORT viewport}, or the center of a specific
219 * {@linkplain ./webdriver.WebElement WebElement}.
220 *
221 * You may adjust how long the remote end should take, in milliseconds, to
222 * perform the move using the `duration` parameter (defaults to 100 ms).
223 * The number of incremental move events generated over this duration is an
224 * implementation detail for the remote end.
225 *
226 * Defaults to moving the mouse to the top-left
227 * corner of the viewport over 100ms.
228 */
229 move(direction: IDirection): Actions;
230
231 /**
232 * Convenience function for performing a 'drag and drop' manuever. The target
233 * element may be moved to the location of another element, or by an offset (in
234 * pixels).
235 */
236 dragAndDrop(
237 from: WebElement,
238 to?: WebElement | { x?: number | string | undefined; y?: number | string | undefined } | null,
239 ): Actions;
240
241 /**
242 * Short-hand for performing a simple left-click (down/up) with the mouse.
243 *
244 * @param {./WebElement=} element If specified, the mouse will
245 * first be moved to the center of the element before performing the
246 * click.
247 * @return {!Actions} a self reference.
248 */
249 click(element?: WebElement): Actions;
250
251 /**
252 * Short-hand for performing a double left-click with the mouse.
253 *
254 * @param {./WebElement=} element If specified, the mouse will
255 * first be moved to the center of the element before performing the
256 * click.
257 * @return {!Actions} a self reference.
258 */
259 doubleClick(element?: WebElement): Actions;
260
261 /**
262 * Short-hand for performing a simple right-click (down/up) with the mouse.
263 *
264 * @param {./WebElement=} element If specified, the mouse will
265 * first be moved to the center of the element before performing the
266 * click.
267 * @return {!Actions} a self reference.
268 */
269 contextClick(element?: WebElement): Actions;
270
271 /**
272 * Performs a modifier key press. The modifier key is <em>not released</em>
273 * until {@link #keyUp} or {@link #sendKeys} is called. The key press will be
274 * targetted at the currently focused element.
275 * @param {!Key} key The modifier key to push. Must be one of
276 * {ALT, CONTROL, SHIFT, COMMAND, META}.
277 * @return {!Actions} A self reference.
278 * @throws {Error} If the key is not a valid modifier key.
279 */
280 keyDown(key: string): Actions;
281
282 /**
283 * Performs a modifier key release. The release is targetted at the currently
284 * focused element.
285 * @param {!Key} key The modifier key to release. Must be one of
286 * {ALT, CONTROL, SHIFT, COMMAND, META}.
287 * @return {!Actions} A self reference.
288 * @throws {Error} If the key is not a valid modifier key.
289 */
290 keyUp(key: string): Actions;
291
292 /**
293 * Simulates typing multiple keys. Each modifier key encountered in the
294 * sequence will not be released until it is encountered again. All key events
295 * will be targeted at the currently focused element.
296 *
297 * @param {...(string|!input.Key|!Array<(string|!input.Key)>)} var_args
298 * The keys to type.
299 * @return {!Actions} A self reference.
300 * @throws {Error} If the key is not a valid modifier key.
301 */
302 sendKeys(...var_args: Array<string | Promise<string>>): Actions;
303
304 // endregion
305}