1 | // Licensed to the Software Freedom Conservancy (SFC) under one
|
2 | // or more contributor license agreements. See the NOTICE file
|
3 | // distributed with this work for additional information
|
4 | // regarding copyright ownership. The SFC licenses this file
|
5 | // to you under the Apache License, Version 2.0 (the
|
6 | // "License"); you may not use this file except in compliance
|
7 | // with the License. You may obtain a copy of the License at
|
8 | //
|
9 | // http://www.apache.org/licenses/LICENSE-2.0
|
10 | //
|
11 | // Unless required by applicable law or agreed to in writing,
|
12 | // software distributed under the License is distributed on an
|
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14 | // KIND, either express or implied. See the License for the
|
15 | // specific language governing permissions and limitations
|
16 | // under the License.
|
17 |
|
18 | ;
|
19 |
|
20 | /**
|
21 | * @fileoverview Defines types related to user input with the WebDriver API.
|
22 | */
|
23 |
|
24 |
|
25 | /**
|
26 | * Enumeration of the buttons used in the advanced interactions API.
|
27 | * @enum {number}
|
28 | */
|
29 | const Button = {
|
30 | LEFT: 0,
|
31 | MIDDLE: 1,
|
32 | RIGHT: 2
|
33 | };
|
34 |
|
35 |
|
36 |
|
37 | /**
|
38 | * Representations of pressable keys that aren't text. These are stored in
|
39 | * the Unicode PUA (Private Use Area) code points, 0xE000-0xF8FF. Refer to
|
40 | * http://www.google.com.au/search?&q=unicode+pua&btnG=Search
|
41 | *
|
42 | * @enum {string}
|
43 | */
|
44 | const Key = {
|
45 | NULL: '\uE000',
|
46 | CANCEL: '\uE001', // ^break
|
47 | HELP: '\uE002',
|
48 | BACK_SPACE: '\uE003',
|
49 | TAB: '\uE004',
|
50 | CLEAR: '\uE005',
|
51 | RETURN: '\uE006',
|
52 | ENTER: '\uE007',
|
53 | SHIFT: '\uE008',
|
54 | CONTROL: '\uE009',
|
55 | ALT: '\uE00A',
|
56 | PAUSE: '\uE00B',
|
57 | ESCAPE: '\uE00C',
|
58 | SPACE: '\uE00D',
|
59 | PAGE_UP: '\uE00E',
|
60 | PAGE_DOWN: '\uE00F',
|
61 | END: '\uE010',
|
62 | HOME: '\uE011',
|
63 | ARROW_LEFT: '\uE012',
|
64 | LEFT: '\uE012',
|
65 | ARROW_UP: '\uE013',
|
66 | UP: '\uE013',
|
67 | ARROW_RIGHT: '\uE014',
|
68 | RIGHT: '\uE014',
|
69 | ARROW_DOWN: '\uE015',
|
70 | DOWN: '\uE015',
|
71 | INSERT: '\uE016',
|
72 | DELETE: '\uE017',
|
73 | SEMICOLON: '\uE018',
|
74 | EQUALS: '\uE019',
|
75 |
|
76 | NUMPAD0: '\uE01A', // number pad keys
|
77 | NUMPAD1: '\uE01B',
|
78 | NUMPAD2: '\uE01C',
|
79 | NUMPAD3: '\uE01D',
|
80 | NUMPAD4: '\uE01E',
|
81 | NUMPAD5: '\uE01F',
|
82 | NUMPAD6: '\uE020',
|
83 | NUMPAD7: '\uE021',
|
84 | NUMPAD8: '\uE022',
|
85 | NUMPAD9: '\uE023',
|
86 | MULTIPLY: '\uE024',
|
87 | ADD: '\uE025',
|
88 | SEPARATOR: '\uE026',
|
89 | SUBTRACT: '\uE027',
|
90 | DECIMAL: '\uE028',
|
91 | DIVIDE: '\uE029',
|
92 |
|
93 | F1: '\uE031', // function keys
|
94 | F2: '\uE032',
|
95 | F3: '\uE033',
|
96 | F4: '\uE034',
|
97 | F5: '\uE035',
|
98 | F6: '\uE036',
|
99 | F7: '\uE037',
|
100 | F8: '\uE038',
|
101 | F9: '\uE039',
|
102 | F10: '\uE03A',
|
103 | F11: '\uE03B',
|
104 | F12: '\uE03C',
|
105 |
|
106 | COMMAND: '\uE03D', // Apple command key
|
107 | META: '\uE03D' // alias for Windows key
|
108 | };
|
109 |
|
110 |
|
111 | /**
|
112 | * Simulate pressing many keys at once in a "chord". Takes a sequence of
|
113 | * {@linkplain Key keys} or strings, appends each of the values to a string,
|
114 | * adds the chord termination key ({@link Key.NULL}) and returns the resulting
|
115 | * string.
|
116 | *
|
117 | * Note: when the low-level webdriver key handlers see Keys.NULL, active
|
118 | * modifier keys (CTRL/ALT/SHIFT/etc) release via a keyup event.
|
119 | *
|
120 | * @param {...string} var_args The key sequence to concatenate.
|
121 | * @return {string} The null-terminated key sequence.
|
122 | */
|
123 | Key.chord = function(var_args) {
|
124 | return Array.prototype.slice.call(arguments, 0).join('') + Key.NULL;
|
125 | };
|
126 |
|
127 |
|
128 | /**
|
129 | * Used with {@link ./webelement.WebElement#sendKeys WebElement#sendKeys} on
|
130 | * file input elements (`<input type="file">`) to detect when the entered key
|
131 | * sequence defines the path to a file.
|
132 | *
|
133 | * By default, {@linkplain ./webelement.WebElement WebElement's} will enter all
|
134 | * key sequences exactly as entered. You may set a
|
135 | * {@linkplain ./webdriver.WebDriver#setFileDetector file detector} on the
|
136 | * parent WebDriver instance to define custom behavior for handling file
|
137 | * elements. Of particular note is the
|
138 | * {@link selenium-webdriver/remote.FileDetector}, which should be used when
|
139 | * running against a remote
|
140 | * [Selenium Server](http://docs.seleniumhq.org/download/).
|
141 | */
|
142 | class FileDetector {
|
143 |
|
144 | /**
|
145 | * Handles the file specified by the given path, preparing it for use with
|
146 | * the current browser. If the path does not refer to a valid file, it will
|
147 | * be returned unchanged, otherwisee a path suitable for use with the current
|
148 | * browser will be returned.
|
149 | *
|
150 | * This default implementation is a no-op. Subtypes may override this function
|
151 | * for custom tailored file handling.
|
152 | *
|
153 | * @param {!./webdriver.WebDriver} driver The driver for the current browser.
|
154 | * @param {string} path The path to process.
|
155 | * @return {!Promise<string>} A promise for the processed file path.
|
156 | * @package
|
157 | */
|
158 | handleFile(driver, path) {
|
159 | return Promise.resolve(path);
|
160 | }
|
161 | }
|
162 |
|
163 |
|
164 | // PUBLIC API
|
165 |
|
166 |
|
167 | module.exports = {
|
168 | Button: Button,
|
169 | Key: Key,
|
170 | FileDetector: FileDetector
|
171 | };
|