2016-01-20 15:19:04 -08:00
|
|
|
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
|
// distributed with this work for additional information
|
|
|
|
|
// regarding copyright ownership. The SFC licenses this file
|
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
|
// "License"); you may not use this file except in compliance
|
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing,
|
|
|
|
|
// software distributed under the License is distributed on an
|
|
|
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
|
// KIND, either express or implied. See the License for the
|
|
|
|
|
// specific language governing permissions and limitations
|
|
|
|
|
// under the License.
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @fileoverview Contains several classes for handling commands.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-08-03 17:56:31 +03:00
|
|
|
'use strict'
|
2016-01-20 15:19:04 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Describes a command to execute.
|
|
|
|
|
* @final
|
|
|
|
|
*/
|
|
|
|
|
class Command {
|
|
|
|
|
/** @param {string} name The name of this command. */
|
|
|
|
|
constructor(name) {
|
|
|
|
|
/** @private {string} */
|
2020-08-03 17:56:31 +03:00
|
|
|
this.name_ = name
|
2016-01-20 15:19:04 -08:00
|
|
|
|
|
|
|
|
/** @private {!Object<*>} */
|
2020-08-03 17:56:31 +03:00
|
|
|
this.parameters_ = {}
|
2016-01-20 15:19:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @return {string} This command's name. */
|
|
|
|
|
getName() {
|
2020-08-03 17:56:31 +03:00
|
|
|
return this.name_
|
2016-01-20 15:19:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets a parameter to send with this command.
|
|
|
|
|
* @param {string} name The parameter name.
|
|
|
|
|
* @param {*} value The parameter value.
|
|
|
|
|
* @return {!Command} A self reference.
|
|
|
|
|
*/
|
|
|
|
|
setParameter(name, value) {
|
2020-08-03 17:56:31 +03:00
|
|
|
this.parameters_[name] = value
|
|
|
|
|
return this
|
2016-01-20 15:19:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the parameters for this command.
|
|
|
|
|
* @param {!Object<*>} parameters The command parameters.
|
|
|
|
|
* @return {!Command} A self reference.
|
|
|
|
|
*/
|
|
|
|
|
setParameters(parameters) {
|
2020-08-03 17:56:31 +03:00
|
|
|
this.parameters_ = parameters
|
|
|
|
|
return this
|
2016-01-20 15:19:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a named command parameter.
|
|
|
|
|
* @param {string} key The parameter key to look up.
|
|
|
|
|
* @return {*} The parameter value, or undefined if it has not been set.
|
|
|
|
|
*/
|
|
|
|
|
getParameter(key) {
|
2020-08-03 17:56:31 +03:00
|
|
|
return this.parameters_[key]
|
2016-01-20 15:19:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return {!Object<*>} The parameters to send with this command.
|
|
|
|
|
*/
|
|
|
|
|
getParameters() {
|
2020-08-03 17:56:31 +03:00
|
|
|
return this.parameters_
|
2016-01-20 15:19:04 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Enumeration of predefined names command names that all command processors
|
|
|
|
|
* will support.
|
|
|
|
|
* @enum {string}
|
|
|
|
|
*/
|
|
|
|
|
const Name = {
|
|
|
|
|
GET_SERVER_STATUS: 'getStatus',
|
|
|
|
|
|
|
|
|
|
NEW_SESSION: 'newSession',
|
|
|
|
|
GET_SESSIONS: 'getSessions',
|
|
|
|
|
|
|
|
|
|
CLOSE: 'close',
|
|
|
|
|
QUIT: 'quit',
|
|
|
|
|
|
|
|
|
|
GET_CURRENT_URL: 'getCurrentUrl',
|
|
|
|
|
GET: 'get',
|
|
|
|
|
GO_BACK: 'goBack',
|
|
|
|
|
GO_FORWARD: 'goForward',
|
|
|
|
|
REFRESH: 'refresh',
|
|
|
|
|
|
|
|
|
|
ADD_COOKIE: 'addCookie',
|
|
|
|
|
GET_COOKIE: 'getCookie',
|
|
|
|
|
GET_ALL_COOKIES: 'getCookies',
|
|
|
|
|
DELETE_COOKIE: 'deleteCookie',
|
|
|
|
|
DELETE_ALL_COOKIES: 'deleteAllCookies',
|
|
|
|
|
|
|
|
|
|
GET_ACTIVE_ELEMENT: 'getActiveElement',
|
|
|
|
|
FIND_ELEMENT: 'findElement',
|
|
|
|
|
FIND_ELEMENTS: 'findElements',
|
2020-08-03 17:56:31 +03:00
|
|
|
FIND_ELEMENTS_RELATIVE: 'findElementsRelative',
|
2016-01-20 15:19:04 -08:00
|
|
|
FIND_CHILD_ELEMENT: 'findChildElement',
|
|
|
|
|
FIND_CHILD_ELEMENTS: 'findChildElements',
|
|
|
|
|
|
|
|
|
|
CLEAR_ELEMENT: 'clearElement',
|
|
|
|
|
CLICK_ELEMENT: 'clickElement',
|
|
|
|
|
SEND_KEYS_TO_ELEMENT: 'sendKeysToElement',
|
|
|
|
|
|
|
|
|
|
GET_CURRENT_WINDOW_HANDLE: 'getCurrentWindowHandle',
|
|
|
|
|
GET_WINDOW_HANDLES: 'getWindowHandles',
|
2017-10-14 19:47:12 -07:00
|
|
|
GET_WINDOW_RECT: 'getWindowRect',
|
|
|
|
|
SET_WINDOW_RECT: 'setWindowRect',
|
2016-01-20 15:19:04 -08:00
|
|
|
MAXIMIZE_WINDOW: 'maximizeWindow',
|
2017-10-08 21:14:28 -07:00
|
|
|
MINIMIZE_WINDOW: 'minimizeWindow',
|
|
|
|
|
FULLSCREEN_WINDOW: 'fullscreenWindow',
|
2016-01-20 15:19:04 -08:00
|
|
|
|
|
|
|
|
SWITCH_TO_WINDOW: 'switchToWindow',
|
2019-02-20 17:01:52 +02:00
|
|
|
SWITCH_TO_NEW_WINDOW: 'newWindow',
|
2016-01-20 15:19:04 -08:00
|
|
|
SWITCH_TO_FRAME: 'switchToFrame',
|
2017-12-27 15:12:04 -08:00
|
|
|
SWITCH_TO_FRAME_PARENT: 'switchToFrameParent',
|
2016-01-20 15:19:04 -08:00
|
|
|
GET_PAGE_SOURCE: 'getPageSource',
|
|
|
|
|
GET_TITLE: 'getTitle',
|
|
|
|
|
|
|
|
|
|
EXECUTE_SCRIPT: 'executeScript',
|
|
|
|
|
EXECUTE_ASYNC_SCRIPT: 'executeAsyncScript',
|
|
|
|
|
|
|
|
|
|
GET_ELEMENT_TEXT: 'getElementText',
|
2021-01-04 02:09:32 +05:30
|
|
|
GET_COMPUTED_ROLE: 'getAriaRole',
|
2021-01-22 06:09:28 +05:30
|
|
|
GET_COMPUTED_LABEL: 'getAccessibleName',
|
2016-01-20 15:19:04 -08:00
|
|
|
GET_ELEMENT_TAG_NAME: 'getElementTagName',
|
|
|
|
|
IS_ELEMENT_SELECTED: 'isElementSelected',
|
|
|
|
|
IS_ELEMENT_ENABLED: 'isElementEnabled',
|
|
|
|
|
IS_ELEMENT_DISPLAYED: 'isElementDisplayed',
|
2018-01-07 18:55:16 -08:00
|
|
|
GET_ELEMENT_RECT: 'getElementRect',
|
2016-01-20 15:19:04 -08:00
|
|
|
GET_ELEMENT_ATTRIBUTE: 'getElementAttribute',
|
2021-11-30 16:27:02 +05:30
|
|
|
GET_DOM_ATTRIBUTE: 'getDomAttribute',
|
2016-01-20 15:19:04 -08:00
|
|
|
GET_ELEMENT_VALUE_OF_CSS_PROPERTY: 'getElementValueOfCssProperty',
|
2019-12-04 00:11:19 +05:30
|
|
|
GET_ELEMENT_PROPERTY: 'getElementProperty',
|
2016-01-20 15:19:04 -08:00
|
|
|
|
|
|
|
|
SCREENSHOT: 'screenshot',
|
|
|
|
|
TAKE_ELEMENT_SCREENSHOT: 'takeElementScreenshot',
|
2017-03-08 19:54:54 -08:00
|
|
|
|
2020-11-24 17:38:33 +05:30
|
|
|
PRINT_PAGE: 'printPage',
|
|
|
|
|
|
2017-03-08 19:54:54 -08:00
|
|
|
GET_TIMEOUT: 'getTimeout',
|
2016-01-20 15:19:04 -08:00
|
|
|
SET_TIMEOUT: 'setTimeout',
|
|
|
|
|
|
|
|
|
|
ACCEPT_ALERT: 'acceptAlert',
|
|
|
|
|
DISMISS_ALERT: 'dismissAlert',
|
|
|
|
|
GET_ALERT_TEXT: 'getAlertText',
|
|
|
|
|
SET_ALERT_TEXT: 'setAlertValue',
|
|
|
|
|
|
2021-11-16 21:05:25 +00:00
|
|
|
// Shadow DOM Commands
|
|
|
|
|
GET_SHADOW_ROOT: 'getShadowRoot',
|
|
|
|
|
FIND_ELEMENT_FROM_SHADOWROOT: 'findElementFromShadowRoot',
|
|
|
|
|
FIND_ELEMENTS_FROM_SHADOWROOT: 'findElementsFromShadowRoot',
|
|
|
|
|
|
2022-05-31 11:40:57 +05:30
|
|
|
// Virtual Authenticator Commands
|
2022-06-02 23:41:17 +05:30
|
|
|
ADD_VIRTUAL_AUTHENTICATOR: 'addVirtualAuthenticator',
|
|
|
|
|
REMOVE_VIRTUAL_AUTHENTICATOR: 'removeVirtualAuthenticator',
|
|
|
|
|
ADD_CREDENTIAL: 'addCredential',
|
|
|
|
|
GET_CREDENTIALS: 'getCredentials',
|
|
|
|
|
REMOVE_CREDENTIAL: 'removeCredential',
|
|
|
|
|
REMOVE_ALL_CREDENTIALS: 'removeAllCredentials',
|
|
|
|
|
SET_USER_VERIFIED: 'setUserVerified',
|
2022-05-31 11:40:57 +05:30
|
|
|
|
2016-01-20 15:19:04 -08:00
|
|
|
GET_AVAILABLE_LOG_TYPES: 'getAvailableLogTypes',
|
|
|
|
|
GET_LOG: 'getLog',
|
|
|
|
|
|
|
|
|
|
// Non-standard commands used by the standalone Selenium server.
|
2017-10-08 20:05:35 -07:00
|
|
|
UPLOAD_FILE: 'uploadFile',
|
2017-10-08 20:26:39 -07:00
|
|
|
|
2017-10-08 20:05:35 -07:00
|
|
|
ACTIONS: 'actions',
|
|
|
|
|
CLEAR_ACTIONS: 'clearActions',
|
2024-01-02 21:17:53 -06:00
|
|
|
|
2024-02-07 16:07:24 +00:00
|
|
|
GET_DOWNLOADABLE_FILES: 'getDownloadableFiles',
|
|
|
|
|
DOWNLOAD_FILE: 'downloadFile',
|
|
|
|
|
DELETE_DOWNLOADABLE_FILES: 'deleteDownloadableFiles',
|
2025-01-06 15:09:34 +05:30
|
|
|
|
|
|
|
|
// Federated Credential Management API
|
|
|
|
|
// https://www.w3.org/TR/fedcm/#automation
|
|
|
|
|
CANCEL_DIALOG: 'cancelDialog',
|
|
|
|
|
SELECT_ACCOUNT: 'selectAccount',
|
|
|
|
|
GET_ACCOUNTS: 'getAccounts',
|
|
|
|
|
GET_FEDCM_TITLE: 'getFedCmTitle',
|
|
|
|
|
GET_FEDCM_DIALOG_TYPE: 'getFedCmDialogType',
|
|
|
|
|
SET_DELAY_ENABLED: 'setDelayEnabled',
|
|
|
|
|
RESET_COOLDOWN: 'resetCooldown',
|
|
|
|
|
CLICK_DIALOG_BUTTON: 'clickdialogbutton',
|
2020-08-03 17:56:31 +03:00
|
|
|
}
|
2016-01-20 15:19:04 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handles the execution of WebDriver {@link Command commands}.
|
2017-12-20 22:07:25 -08:00
|
|
|
* @record
|
2016-01-20 15:19:04 -08:00
|
|
|
*/
|
|
|
|
|
class Executor {
|
|
|
|
|
/**
|
|
|
|
|
* Executes the given {@code command}. If there is an error executing the
|
|
|
|
|
* command, the provided callback will be invoked with the offending error.
|
|
|
|
|
* Otherwise, the callback will be invoked with a null Error and non-null
|
|
|
|
|
* response object.
|
|
|
|
|
*
|
|
|
|
|
* @param {!Command} command The command to execute.
|
2016-06-08 08:26:34 -07:00
|
|
|
* @return {!Promise<?>} A promise that will be fulfilled with the command
|
|
|
|
|
* result.
|
2016-01-20 15:19:04 -08:00
|
|
|
*/
|
2020-08-03 17:56:31 +03:00
|
|
|
execute(command) {} // eslint-disable-line
|
2016-01-20 15:19:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PUBLIC API
|
|
|
|
|
|
2016-03-12 11:49:57 -08:00
|
|
|
module.exports = {
|
2022-08-28 11:26:01 +03:00
|
|
|
Command,
|
|
|
|
|
Name,
|
|
|
|
|
Executor,
|
2020-08-03 17:56:31 +03:00
|
|
|
}
|