UNPKG

6.99 kBJavaScriptView Raw
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 * @fileoverview Contains several classes for handling commands.
20 */
21
22'use strict';
23
24/**
25 * Describes a command to execute.
26 * @final
27 */
28class Command {
29 /** @param {string} name The name of this command. */
30 constructor(name) {
31 /** @private {string} */
32 this.name_ = name;
33
34 /** @private {!Object<*>} */
35 this.parameters_ = {};
36 }
37
38 /** @return {string} This command's name. */
39 getName() {
40 return this.name_;
41 }
42
43 /**
44 * Sets a parameter to send with this command.
45 * @param {string} name The parameter name.
46 * @param {*} value The parameter value.
47 * @return {!Command} A self reference.
48 */
49 setParameter(name, value) {
50 this.parameters_[name] = value;
51 return this;
52 }
53
54 /**
55 * Sets the parameters for this command.
56 * @param {!Object<*>} parameters The command parameters.
57 * @return {!Command} A self reference.
58 */
59 setParameters(parameters) {
60 this.parameters_ = parameters;
61 return this;
62 }
63
64 /**
65 * Returns a named command parameter.
66 * @param {string} key The parameter key to look up.
67 * @return {*} The parameter value, or undefined if it has not been set.
68 */
69 getParameter(key) {
70 return this.parameters_[key];
71 }
72
73 /**
74 * @return {!Object<*>} The parameters to send with this command.
75 */
76 getParameters() {
77 return this.parameters_;
78 }
79}
80
81
82/**
83 * Enumeration of predefined names command names that all command processors
84 * will support.
85 * @enum {string}
86 */
87// TODO: Delete obsolete command names.
88const Name = {
89 GET_SERVER_STATUS: 'getStatus',
90
91 NEW_SESSION: 'newSession',
92 GET_SESSIONS: 'getSessions',
93 DESCRIBE_SESSION: 'getSessionCapabilities',
94
95 CLOSE: 'close',
96 QUIT: 'quit',
97
98 GET_CURRENT_URL: 'getCurrentUrl',
99 GET: 'get',
100 GO_BACK: 'goBack',
101 GO_FORWARD: 'goForward',
102 REFRESH: 'refresh',
103
104 ADD_COOKIE: 'addCookie',
105 GET_COOKIE: 'getCookie',
106 GET_ALL_COOKIES: 'getCookies',
107 DELETE_COOKIE: 'deleteCookie',
108 DELETE_ALL_COOKIES: 'deleteAllCookies',
109
110 GET_ACTIVE_ELEMENT: 'getActiveElement',
111 FIND_ELEMENT: 'findElement',
112 FIND_ELEMENTS: 'findElements',
113 FIND_CHILD_ELEMENT: 'findChildElement',
114 FIND_CHILD_ELEMENTS: 'findChildElements',
115
116 CLEAR_ELEMENT: 'clearElement',
117 CLICK_ELEMENT: 'clickElement',
118 SEND_KEYS_TO_ELEMENT: 'sendKeysToElement',
119 SUBMIT_ELEMENT: 'submitElement',
120
121 GET_CURRENT_WINDOW_HANDLE: 'getCurrentWindowHandle',
122 GET_WINDOW_HANDLES: 'getWindowHandles',
123 GET_WINDOW_POSITION: 'getWindowPosition',
124 SET_WINDOW_POSITION: 'setWindowPosition',
125 GET_WINDOW_SIZE: 'getWindowSize',
126 SET_WINDOW_SIZE: 'setWindowSize',
127 MAXIMIZE_WINDOW: 'maximizeWindow',
128
129 SWITCH_TO_WINDOW: 'switchToWindow',
130 SWITCH_TO_FRAME: 'switchToFrame',
131 GET_PAGE_SOURCE: 'getPageSource',
132 GET_TITLE: 'getTitle',
133
134 EXECUTE_SCRIPT: 'executeScript',
135 EXECUTE_ASYNC_SCRIPT: 'executeAsyncScript',
136
137 GET_ELEMENT_TEXT: 'getElementText',
138 GET_ELEMENT_TAG_NAME: 'getElementTagName',
139 IS_ELEMENT_SELECTED: 'isElementSelected',
140 IS_ELEMENT_ENABLED: 'isElementEnabled',
141 IS_ELEMENT_DISPLAYED: 'isElementDisplayed',
142 GET_ELEMENT_LOCATION: 'getElementLocation',
143 GET_ELEMENT_LOCATION_IN_VIEW: 'getElementLocationOnceScrolledIntoView',
144 GET_ELEMENT_SIZE: 'getElementSize',
145 GET_ELEMENT_ATTRIBUTE: 'getElementAttribute',
146 GET_ELEMENT_VALUE_OF_CSS_PROPERTY: 'getElementValueOfCssProperty',
147 ELEMENT_EQUALS: 'elementEquals',
148
149 SCREENSHOT: 'screenshot',
150 TAKE_ELEMENT_SCREENSHOT: 'takeElementScreenshot',
151 IMPLICITLY_WAIT: 'implicitlyWait',
152 SET_SCRIPT_TIMEOUT: 'setScriptTimeout',
153 SET_TIMEOUT: 'setTimeout',
154
155 ACCEPT_ALERT: 'acceptAlert',
156 DISMISS_ALERT: 'dismissAlert',
157 GET_ALERT_TEXT: 'getAlertText',
158 SET_ALERT_TEXT: 'setAlertValue',
159 SET_ALERT_CREDENTIALS: 'setAlertCredentials',
160
161 EXECUTE_SQL: 'executeSQL',
162 GET_LOCATION: 'getLocation',
163 SET_LOCATION: 'setLocation',
164 GET_APP_CACHE: 'getAppCache',
165 GET_APP_CACHE_STATUS: 'getStatus',
166 CLEAR_APP_CACHE: 'clearAppCache',
167 IS_BROWSER_ONLINE: 'isBrowserOnline',
168 SET_BROWSER_ONLINE: 'setBrowserOnline',
169
170 GET_LOCAL_STORAGE_ITEM: 'getLocalStorageItem',
171 GET_LOCAL_STORAGE_KEYS: 'getLocalStorageKeys',
172 SET_LOCAL_STORAGE_ITEM: 'setLocalStorageItem',
173 REMOVE_LOCAL_STORAGE_ITEM: 'removeLocalStorageItem',
174 CLEAR_LOCAL_STORAGE: 'clearLocalStorage',
175 GET_LOCAL_STORAGE_SIZE: 'getLocalStorageSize',
176
177 GET_SESSION_STORAGE_ITEM: 'getSessionStorageItem',
178 GET_SESSION_STORAGE_KEYS: 'getSessionStorageKey',
179 SET_SESSION_STORAGE_ITEM: 'setSessionStorageItem',
180 REMOVE_SESSION_STORAGE_ITEM: 'removeSessionStorageItem',
181 CLEAR_SESSION_STORAGE: 'clearSessionStorage',
182 GET_SESSION_STORAGE_SIZE: 'getSessionStorageSize',
183
184 SET_SCREEN_ORIENTATION: 'setScreenOrientation',
185 GET_SCREEN_ORIENTATION: 'getScreenOrientation',
186
187 // These belong to the Advanced user interactions - an element is
188 // optional for these commands.
189 CLICK: 'mouseClick',
190 DOUBLE_CLICK: 'mouseDoubleClick',
191 MOUSE_DOWN: 'mouseButtonDown',
192 MOUSE_UP: 'mouseButtonUp',
193 MOVE_TO: 'mouseMoveTo',
194 SEND_KEYS_TO_ACTIVE_ELEMENT: 'sendKeysToActiveElement',
195
196 // These belong to the Advanced Touch API
197 TOUCH_SINGLE_TAP: 'touchSingleTap',
198 TOUCH_DOWN: 'touchDown',
199 TOUCH_UP: 'touchUp',
200 TOUCH_MOVE: 'touchMove',
201 TOUCH_SCROLL: 'touchScroll',
202 TOUCH_DOUBLE_TAP: 'touchDoubleTap',
203 TOUCH_LONG_PRESS: 'touchLongPress',
204 TOUCH_FLICK: 'touchFlick',
205
206 GET_AVAILABLE_LOG_TYPES: 'getAvailableLogTypes',
207 GET_LOG: 'getLog',
208 GET_SESSION_LOGS: 'getSessionLogs',
209
210 // Non-standard commands used by the standalone Selenium server.
211 UPLOAD_FILE: 'uploadFile'
212};
213
214
215
216/**
217 * Handles the execution of WebDriver {@link Command commands}.
218 * @interface
219 */
220class Executor {
221 /**
222 * Executes the given {@code command}. If there is an error executing the
223 * command, the provided callback will be invoked with the offending error.
224 * Otherwise, the callback will be invoked with a null Error and non-null
225 * response object.
226 *
227 * @param {!Command} command The command to execute.
228 * @return {!Promise<?>} A promise that will be fulfilled with the command
229 * result.
230 */
231 execute(command) {}
232}
233
234
235
236// PUBLIC API
237
238
239module.exports = {
240 Command: Command,
241 Name: Name,
242 Executor: Executor
243};