Configuration options and capabilities specific to each supported browser including Chrome, Firefox, Safari, Edge, and Internet Explorer.
Chrome-specific configuration for Chromium-based browsers including Chrome and Edge.
/**
* Chrome browser options and configuration
*/
class chrome.Options extends Capabilities {
constructor();
/** Add Chrome command line arguments */
addArguments(...args: string[]): chrome.Options;
/** Add Chrome extensions from file paths */
addExtensions(...paths: string[]): chrome.Options;
/** Set Chrome binary executable path */
setChromeBinaryPath(path: string): chrome.Options;
/** Set user preferences */
setUserPreferences(prefs: object): chrome.Options;
/** Configure mobile device emulation */
setMobileEmulation(config: object): chrome.Options;
/** Set Chrome log file path */
setChromeLogFile(path: string): chrome.Options;
/** Set Chrome crash dump path */
setChromeMinidumpPath(path: string): chrome.Options;
/** Configure for Android Chrome */
androidChrome(): chrome.Options;
/** Set Android package name */
androidPackage(pkg: string): chrome.Options;
/** Set Android activity */
androidActivity(activity: string): chrome.Options;
/** Set Android device serial */
androidDeviceSerial(serial: string): chrome.Options;
}
/**
* Chrome service configuration
*/
class chrome.ServiceBuilder {
constructor(executable?: string);
/** Set ChromeDriver executable path */
setExecutable(executable: string): chrome.ServiceBuilder;
/** Set service port */
setPort(port: number): chrome.ServiceBuilder;
/** Enable verbose logging */
enableVerboseLogging(): chrome.ServiceBuilder;
/** Set log file path */
setLogFile(path: string): chrome.ServiceBuilder;
/** Build service instance */
build(): object;
}Usage Examples:
const { Builder } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
// Basic Chrome options
let options = new chrome.Options();
options.addArguments('--headless');
options.addArguments('--no-sandbox');
options.addArguments('--disable-dev-shm-usage');
let driver = await new Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();
// Advanced Chrome configuration
let advancedOptions = new chrome.Options();
advancedOptions
.addArguments('--start-maximized')
.addArguments('--disable-extensions')
.addArguments('--disable-gpu')
.setChromeBinaryPath('/usr/bin/google-chrome-stable')
.setUserPreferences({
'profile.default_content_setting_values.notifications': 2,
'profile.default_content_settings.popups': 0
});
// Mobile emulation
let mobileOptions = new chrome.Options();
mobileOptions.setMobileEmulation({
deviceName: 'iPhone 12 Pro'
});
// Custom mobile device
let customMobileOptions = new chrome.Options();
customMobileOptions.setMobileEmulation({
deviceMetrics: {
width: 375,
height: 812,
pixelRatio: 3.0
},
userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X)...'
});
// Chrome service
let service = new chrome.ServiceBuilder()
.setPort(9515)
.enableVerboseLogging()
.setLogFile('/tmp/chromedriver.log')
.build();
let serviceDriver = await new Builder()
.forBrowser('chrome')
.setChromeService(service)
.setChromeOptions(options)
.build();Firefox-specific configuration including profiles, preferences, and extensions.
/**
* Firefox browser options and configuration
*/
class firefox.Options extends Capabilities {
constructor();
/** Set Firefox binary executable path */
setBinary(binary: string): firefox.Options;
/** Set Firefox profile */
setProfile(profile: firefox.Profile): firefox.Options;
/** Add Firefox command line arguments */
addArguments(...args: string[]): firefox.Options;
/** Add Firefox extensions from file paths */
addExtensions(...paths: string[]): firefox.Options;
/** Set Firefox preference */
setPreference(key: string, value: any): firefox.Options;
/** Set window size */
windowSize(size: {width: number, height: number}): firefox.Options;
/** Enable mobile mode for Firefox */
enableMobile(androidPackage?: string, androidActivity?: string, deviceSerial?: string): firefox.Options;
/** Enable remote debugging */
enableDebugger(port?: number): firefox.Options;
/** Enable BiDi protocol */
enableBidi(): firefox.Options;
}
/**
* Firefox profile management
*/
class firefox.Profile {
constructor(profileDir?: string);
/** Set preference value */
setPreference(key: string, value: any): void;
/** Add extension from file path */
addExtension(path: string): Promise<void>;
/** Set user agent string */
setUserAgent(userAgent: string): void;
/** Accept untrusted certificates */
setAcceptUntrustedCerts(accept: boolean): void;
/** Assume untrusted certificate issuer */
setAssumeUntrustedCertIssuer(assume: boolean): void;
/** Set native events enabled */
setNativeEventsEnabled(enabled: boolean): void;
}
/**
* Firefox service configuration
*/
class firefox.ServiceBuilder {
constructor(executable?: string);
/** Set GeckoDriver executable path */
setExecutable(executable: string): firefox.ServiceBuilder;
/** Set service port */
setPort(port: number): firefox.ServiceBuilder;
/** Enable verbose logging */
enableVerboseLogging(): firefox.ServiceBuilder;
/** Set log file path */
setLogFile(path: string): firefox.ServiceBuilder;
/** Build service instance */
build(): object;
}Usage Examples:
const { Builder } = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
// Basic Firefox options
let options = new firefox.Options();
options.addArguments('-headless');
options.setBinary('/usr/bin/firefox');
let driver = await new Builder()
.forBrowser('firefox')
.setFirefoxOptions(options)
.build();
// Firefox with custom profile
let profile = new firefox.Profile();
profile.setPreference('browser.download.folderList', 2);
profile.setPreference('browser.download.dir', '/tmp/downloads');
profile.setPreference('browser.helperApps.neverAsk.saveToDisk', 'application/pdf');
let profileOptions = new firefox.Options();
profileOptions.setProfile(profile);
// Firefox with preferences
let prefOptions = new firefox.Options();
prefOptions
.setPreference('dom.webnotifications.enabled', false)
.setPreference('media.volume_scale', '0.0')
.setPreference('geo.enabled', false)
.windowSize({width: 1280, height: 1024});
// Firefox service
let service = new firefox.ServiceBuilder()
.setPort(4444)
.enableVerboseLogging()
.setLogFile('/tmp/geckodriver.log')
.build();Safari-specific configuration for macOS Safari browser.
/**
* Safari browser options and configuration
*/
class safari.Options extends Capabilities {
constructor();
/** Use Safari Technology Preview */
setTechnologyPreview(enabled: boolean): safari.Options;
/** Set logging level */
setLogLevel(level: string): safari.Options;
/** Enable diagnostic logging */
enableLogging(): safari.Options;
}
/**
* Safari service configuration
*/
class safari.ServiceBuilder {
constructor(executable?: string);
/** Set SafariDriver executable path */
setExecutable(executable: string): safari.ServiceBuilder;
/** Set service port */
setPort(port: number): safari.ServiceBuilder;
/** Enable verbose logging */
enableVerboseLogging(): safari.ServiceBuilder;
/** Build service instance */
build(): object;
}Usage Examples:
const { Builder } = require('selenium-webdriver');
const safari = require('selenium-webdriver/safari');
// Basic Safari options
let options = new safari.Options();
options.setTechnologyPreview(true);
options.enableLogging();
let driver = await new Builder()
.forBrowser('safari')
.setSafariOptions(options)
.build();
// Safari service
let service = new safari.ServiceBuilder()
.setPort(4444)
.enableVerboseLogging()
.build();Microsoft Edge browser configuration using Chromium engine.
/**
* Microsoft Edge browser options and configuration
*/
class edge.Options extends Capabilities {
constructor();
/** Set Edge binary executable path */
setEdgeChromiumBinaryPath(path: string): edge.Options;
/** Enable WebView2 automation */
useWebView(enabled: boolean): edge.Options;
/** Add Edge command line arguments */
addArguments(...args: string[]): edge.Options;
/** Add Edge extensions from file paths */
addExtensions(...paths: string[]): edge.Options;
}
/**
* Edge service configuration
*/
class edge.ServiceBuilder {
constructor(executable?: string);
/** Set EdgeDriver executable path */
setExecutable(executable: string): edge.ServiceBuilder;
/** Set service port */
setPort(port: number): edge.ServiceBuilder;
/** Enable verbose logging */
enableVerboseLogging(): edge.ServiceBuilder;
/** Set log file path */
setLogFile(path: string): edge.ServiceBuilder;
/** Build service instance */
build(): object;
}Usage Examples:
const { Builder } = require('selenium-webdriver');
const edge = require('selenium-webdriver/edge');
// Basic Edge options
let options = new edge.Options();
options.addArguments('--headless');
options.setEdgeChromiumBinaryPath('/usr/bin/microsoft-edge-stable');
let driver = await new Builder()
.forBrowser('MicrosoftEdge')
.setEdgeOptions(options)
.build();
// WebView2 automation
let webViewOptions = new edge.Options();
webViewOptions.useWebView(true);
// Edge service
let service = new edge.ServiceBuilder()
.setPort(9515)
.enableVerboseLogging()
.build();Internet Explorer browser configuration (legacy support).
/**
* Internet Explorer browser options and configuration
*/
class ie.Options extends Capabilities {
constructor();
/** Ignore protected mode settings (use with caution) */
introduceFlakinessByIgnoringProtectedModeSettings(ignore: boolean): ie.Options;
/** Ignore zoom setting */
ignoreZoomSetting(ignore: boolean): ie.Options;
/** Set initial browser URL */
initialBrowserUrl(url: string): ie.Options;
/** Enable persistent hover */
enablePersistentHover(enable: boolean): ie.Options;
/** Require window focus */
requireWindowFocus(require: boolean): ie.Options;
/** Set browser attach timeout */
browserAttachTimeout(timeout: number): ie.Options;
/** Force CreateProcess API */
forceCreateProcessApi(force: boolean): ie.Options;
/** Add browser command switches */
addBrowserCommandSwitches(...switches: string[]): ie.Options;
/** Use per-process proxy */
usePerProcessProxy(enable: boolean): ie.Options;
/** Ensure clean session */
ensureCleanSession(clean: boolean): ie.Options;
/** Set log file path */
setLogFile(file: string): ie.Options;
/** Set logging level */
setLogLevel(level: string): ie.Options;
/** Set scroll behavior */
setScrollBehavior(behavior: string): ie.Options;
}
/**
* Internet Explorer service configuration
*/
class ie.ServiceBuilder {
constructor(executable?: string);
/** Set IEDriverServer executable path */
setExecutable(executable: string): ie.ServiceBuilder;
/** Set service port */
setPort(port: number): ie.ServiceBuilder;
/** Enable verbose logging */
enableVerboseLogging(): ie.ServiceBuilder;
/** Set log file path */
setLogFile(path: string): ie.ServiceBuilder;
/** Build service instance */
build(): object;
}Usage Examples:
const { Builder } = require('selenium-webdriver');
const ie = require('selenium-webdriver/ie');
// Basic IE options
let options = new ie.Options();
options
.introduceFlakinessByIgnoringProtectedModeSettings(true)
.ignoreZoomSetting(true)
.requireWindowFocus(true)
.ensureCleanSession(true);
let driver = await new Builder()
.forBrowser('internet explorer')
.setIeOptions(options)
.build();
// IE service
let service = new ie.ServiceBuilder()
.setPort(5555)
.enableVerboseLogging()
.setLogFile('/tmp/iedriver.log')
.build();Standard constants for browser identification and configuration.
const Browser = {
CHROME: 'chrome',
FIREFOX: 'firefox',
SAFARI: 'safari',
EDGE: 'MicrosoftEdge',
INTERNET_EXPLORER: 'internet explorer'
};
const Platform = {
WINDOWS: 'WINDOWS',
MAC: 'MAC',
LINUX: 'LINUX',
UNIX: 'UNIX',
ANDROID: 'ANDROID',
ANY: 'ANY'
};
// Firefox specific constants
const firefox.Context = {
CONTENT: 'content',
CHROME: 'chrome'
};
const firefox.Channel = {
RELEASE: 'release',
BETA: 'beta',
AURORA: 'aurora',
NIGHTLY: 'nightly'
};
// IE specific constants
const ie.Level = {
OFF: 'OFF',
SEVERE: 'SEVERE',
WARNING: 'WARNING',
INFO: 'INFO',
DEBUG: 'DEBUG',
ALL: 'ALL'
};
const ie.Behavior = {
TOP: 0,
BOTTOM: 1
};Frequently used browser configuration patterns for different testing scenarios.
Usage Examples:
// Headless testing configuration
function getHeadlessOptions(browserName) {
switch (browserName) {
case 'chrome':
let chromeOptions = new chrome.Options();
return chromeOptions
.addArguments('--headless')
.addArguments('--no-sandbox')
.addArguments('--disable-dev-shm-usage')
.addArguments('--disable-gpu');
case 'firefox':
let firefoxOptions = new firefox.Options();
return firefoxOptions.addArguments('-headless');
default:
throw new Error(`Headless mode not configured for ${browserName}`);
}
}
// Performance testing configuration
function getPerformanceOptions() {
let options = new chrome.Options();
options
.addArguments('--enable-precise-memory-info')
.addArguments('--js-flags=--expose-gc')
.setUserPreferences({
'profile.default_content_setting_values': {
'plugins': 1,
'popups': 0,
'geolocation': 0,
'notifications': 0,
'media_stream': 0
}
});
return options;
}
// Download handling configuration
function getDownloadOptions(downloadPath) {
let chromeOptions = new chrome.Options();
chromeOptions.setUserPreferences({
'download.default_directory': downloadPath,
'download.prompt_for_download': false,
'plugins.always_open_pdf_externally': true
});
let firefoxProfile = new firefox.Profile();
firefoxProfile.setPreference('browser.download.folderList', 2);
firefoxProfile.setPreference('browser.download.dir', downloadPath);
firefoxProfile.setPreference('browser.helperApps.neverAsk.saveToDisk', 'application/pdf,text/csv');
let firefoxOptions = new firefox.Options();
firefoxOptions.setProfile(firefoxProfile);
return { chrome: chromeOptions, firefox: firefoxOptions };
}