Implementation:Webdriverio Webdriverio WebDriver Constants
| Knowledge Sources | |
|---|---|
| Domains | WebDriver, Configuration |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
The WebDriver_Constants module defines the default configuration schema, well-known element keys, and utility constants used throughout the WebDriver package.
Description
This module exports five constants. DEFAULTS is a typed configuration definition object (Options.Definition<Required<RemoteConfig>>) specifying all WebDriver connection options with their types, default values, and validation logic. It covers: protocol (http/https), hostname (localhost), port, path (must start with /), queryParams, user/key for cloud authentication, capabilities (required), logLevel, outputDir, connectionRetryTimeout (120000ms), connectionRetryCount (3), headers, transformRequest/transformResponse hooks, enableDirectConnect for Appium, strictSSL, cacheDir, and maskingPatterns.
ELEMENT_KEY and SHADOW_ELEMENT_KEY are the W3C WebDriver element identifier strings used to serialize/deserialize element references. BASE_64_REGEX matches base64-encoded strings. APPIUM_MASKING_HEADER provides the HTTP header for Appium-compatible sensitive data masking.
Usage
Use these constants when initializing WebDriver sessions, validating configuration, or working with element references. DEFAULTS is used by the session initialization logic and options validation. The element keys are used across the framework for element serialization.
Code Reference
Source Location
- Repository: Webdriverio_Webdriverio
- File: packages/webdriver/src/constants.ts
Signature
export const DEFAULTS: Options.Definition<Required<RemoteConfig>> = {
protocol: { type: 'string', default: 'http', match: /(http|https)/ },
hostname: { type: 'string', default: 'localhost' },
port: { type: 'number' },
path: { type: 'string', default: '/', validate: (path: string) => boolean },
queryParams: { type: 'object' },
user: { type: 'string' },
key: { type: 'string' },
capabilities: { type: 'object', required: true },
logLevel: { type: 'string', default: 'info', match: /(trace|debug|info|warn|error|silent)/ },
outputDir: { type: 'string' },
connectionRetryTimeout: { type: 'number', default: 120000 },
connectionRetryCount: { type: 'number', default: 3 },
logLevels: { type: 'object' },
headers: { type: 'object' },
transformRequest: { type: 'function', default: (requestOptions: RequestInit) => requestOptions },
transformResponse: { type: 'function', default: (response: Options.RequestLibResponse) => response },
enableDirectConnect: { type: 'boolean', default: true },
strictSSL: { type: 'boolean', default: true },
cacheDir: { type: 'string', default: /* WEBDRIVER_CACHE_DIR env */ },
maskingPatterns: { type: 'string', default: undefined }
}
export const ELEMENT_KEY = 'element-6066-11e4-a52e-4f735466cecf'
export const SHADOW_ELEMENT_KEY = 'shadow-6066-11e4-a52e-4f735466cecf'
export const BASE_64_REGEX = /^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$/
export const APPIUM_MASKING_HEADER = { 'x-appium-is-sensitive': 'true' }
Import
import { DEFAULTS, ELEMENT_KEY, SHADOW_ELEMENT_KEY, BASE_64_REGEX, APPIUM_MASKING_HEADER } from './constants.js'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| N/A | N/A | N/A | This is a constants-only module with no runtime inputs. |
Outputs
| Name | Type | Description |
|---|---|---|
| DEFAULTS | Options.Definition<Required<RemoteConfig>> |
Configuration schema with types, defaults, and validators for all WebDriver options. |
| ELEMENT_KEY | string |
W3C WebDriver element identifier key: 'element-6066-11e4-a52e-4f735466cecf'.
|
| SHADOW_ELEMENT_KEY | string |
W3C WebDriver shadow element identifier key: 'shadow-6066-11e4-a52e-4f735466cecf'.
|
| BASE_64_REGEX | RegExp |
Pattern to validate base64-encoded strings. |
| APPIUM_MASKING_HEADER | { 'x-appium-is-sensitive': 'true' } |
HTTP header to signal Appium that request body contains sensitive data. |
Usage Examples
import { DEFAULTS, ELEMENT_KEY, SHADOW_ELEMENT_KEY } from './constants.js'
// Access default connection retry timeout
const timeout = DEFAULTS.connectionRetryTimeout.default; // 120000
// Check if a value is an element reference
function isElement(value: Record<string, unknown>): boolean {
return ELEMENT_KEY in value;
}
// Check if a value is a shadow root reference
function isShadowRoot(value: Record<string, unknown>): boolean {
return SHADOW_ELEMENT_KEY in value;
}
// Validate the path option
DEFAULTS.path.validate!('/wd/hub'); // true
// DEFAULTS.path.validate!('wd/hub'); // throws TypeError