lib/webdriver/command.js

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