command.js 6.9 KB

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