Path: blob/trunk/javascript/selenium-webdriver/lib/command.js
2884 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617/**18* @fileoverview Contains several classes for handling commands.19*/2021'use strict'2223/**24* Describes a command to execute.25* @final26*/27class Command {28/** @param {string} name The name of this command. */29constructor(name) {30/** @private {string} */31this.name_ = name3233/** @private {!Object<*>} */34this.parameters_ = {}35}3637/** @return {string} This command's name. */38getName() {39return this.name_40}4142/**43* Sets a parameter to send with this command.44* @param {string} name The parameter name.45* @param {*} value The parameter value.46* @return {!Command} A self reference.47*/48setParameter(name, value) {49this.parameters_[name] = value50return this51}5253/**54* Sets the parameters for this command.55* @param {!Object<*>} parameters The command parameters.56* @return {!Command} A self reference.57*/58setParameters(parameters) {59this.parameters_ = parameters60return this61}6263/**64* Returns a named command parameter.65* @param {string} key The parameter key to look up.66* @return {*} The parameter value, or undefined if it has not been set.67*/68getParameter(key) {69return this.parameters_[key]70}7172/**73* @return {!Object<*>} The parameters to send with this command.74*/75getParameters() {76return this.parameters_77}78}7980/**81* Enumeration of predefined names command names that all command processors82* will support.83* @enum {string}84*/85const Name = {86GET_SERVER_STATUS: 'getStatus',8788NEW_SESSION: 'newSession',89GET_SESSIONS: 'getSessions',9091CLOSE: 'close',92QUIT: 'quit',9394GET_CURRENT_URL: 'getCurrentUrl',95GET: 'get',96GO_BACK: 'goBack',97GO_FORWARD: 'goForward',98REFRESH: 'refresh',99100ADD_COOKIE: 'addCookie',101GET_COOKIE: 'getCookie',102GET_ALL_COOKIES: 'getCookies',103DELETE_COOKIE: 'deleteCookie',104DELETE_ALL_COOKIES: 'deleteAllCookies',105106GET_ACTIVE_ELEMENT: 'getActiveElement',107FIND_ELEMENT: 'findElement',108FIND_ELEMENTS: 'findElements',109FIND_ELEMENTS_RELATIVE: 'findElementsRelative',110FIND_CHILD_ELEMENT: 'findChildElement',111FIND_CHILD_ELEMENTS: 'findChildElements',112113CLEAR_ELEMENT: 'clearElement',114CLICK_ELEMENT: 'clickElement',115SEND_KEYS_TO_ELEMENT: 'sendKeysToElement',116117GET_CURRENT_WINDOW_HANDLE: 'getCurrentWindowHandle',118GET_WINDOW_HANDLES: 'getWindowHandles',119GET_WINDOW_RECT: 'getWindowRect',120SET_WINDOW_RECT: 'setWindowRect',121MAXIMIZE_WINDOW: 'maximizeWindow',122MINIMIZE_WINDOW: 'minimizeWindow',123FULLSCREEN_WINDOW: 'fullscreenWindow',124125SWITCH_TO_WINDOW: 'switchToWindow',126SWITCH_TO_NEW_WINDOW: 'newWindow',127SWITCH_TO_FRAME: 'switchToFrame',128SWITCH_TO_FRAME_PARENT: 'switchToFrameParent',129GET_PAGE_SOURCE: 'getPageSource',130GET_TITLE: 'getTitle',131132EXECUTE_SCRIPT: 'executeScript',133EXECUTE_ASYNC_SCRIPT: 'executeAsyncScript',134135GET_ELEMENT_TEXT: 'getElementText',136GET_COMPUTED_ROLE: 'getAriaRole',137GET_COMPUTED_LABEL: 'getAccessibleName',138GET_ELEMENT_TAG_NAME: 'getElementTagName',139IS_ELEMENT_SELECTED: 'isElementSelected',140IS_ELEMENT_ENABLED: 'isElementEnabled',141IS_ELEMENT_DISPLAYED: 'isElementDisplayed',142GET_ELEMENT_RECT: 'getElementRect',143GET_ELEMENT_ATTRIBUTE: 'getElementAttribute',144GET_DOM_ATTRIBUTE: 'getDomAttribute',145GET_ELEMENT_VALUE_OF_CSS_PROPERTY: 'getElementValueOfCssProperty',146GET_ELEMENT_PROPERTY: 'getElementProperty',147148SCREENSHOT: 'screenshot',149TAKE_ELEMENT_SCREENSHOT: 'takeElementScreenshot',150151PRINT_PAGE: 'printPage',152153GET_TIMEOUT: 'getTimeout',154SET_TIMEOUT: 'setTimeout',155156ACCEPT_ALERT: 'acceptAlert',157DISMISS_ALERT: 'dismissAlert',158GET_ALERT_TEXT: 'getAlertText',159SET_ALERT_TEXT: 'setAlertValue',160161// Shadow DOM Commands162GET_SHADOW_ROOT: 'getShadowRoot',163FIND_ELEMENT_FROM_SHADOWROOT: 'findElementFromShadowRoot',164FIND_ELEMENTS_FROM_SHADOWROOT: 'findElementsFromShadowRoot',165166// Virtual Authenticator Commands167ADD_VIRTUAL_AUTHENTICATOR: 'addVirtualAuthenticator',168REMOVE_VIRTUAL_AUTHENTICATOR: 'removeVirtualAuthenticator',169ADD_CREDENTIAL: 'addCredential',170GET_CREDENTIALS: 'getCredentials',171REMOVE_CREDENTIAL: 'removeCredential',172REMOVE_ALL_CREDENTIALS: 'removeAllCredentials',173SET_USER_VERIFIED: 'setUserVerified',174175GET_AVAILABLE_LOG_TYPES: 'getAvailableLogTypes',176GET_LOG: 'getLog',177178// Non-standard commands used by the standalone Selenium server.179UPLOAD_FILE: 'uploadFile',180181ACTIONS: 'actions',182CLEAR_ACTIONS: 'clearActions',183184GET_DOWNLOADABLE_FILES: 'getDownloadableFiles',185DOWNLOAD_FILE: 'downloadFile',186DELETE_DOWNLOADABLE_FILES: 'deleteDownloadableFiles',187188// Federated Credential Management API189// https://www.w3.org/TR/fedcm/#automation190CANCEL_DIALOG: 'cancelDialog',191SELECT_ACCOUNT: 'selectAccount',192GET_ACCOUNTS: 'getAccounts',193GET_FEDCM_TITLE: 'getFedCmTitle',194GET_FEDCM_DIALOG_TYPE: 'getFedCmDialogType',195SET_DELAY_ENABLED: 'setDelayEnabled',196RESET_COOLDOWN: 'resetCooldown',197CLICK_DIALOG_BUTTON: 'clickdialogbutton',198}199200/**201* Handles the execution of WebDriver {@link Command commands}.202* @record203*/204class Executor {205/**206* Executes the given {@code command}. If there is an error executing the207* command, the provided callback will be invoked with the offending error.208* Otherwise, the callback will be invoked with a null Error and non-null209* response object.210*211* @param {!Command} command The command to execute.212* @return {!Promise<?>} A promise that will be fulfilled with the command213* result.214*/215execute(command) {} // eslint-disable-line216}217218// PUBLIC API219220module.exports = {221Command,222Name,223Executor,224}225226227