A WebdriverIO service to start & stop Selenium Standalone
npx @tessl/cli install tessl/npm-wdio--selenium-standalone-service@7.40.0A WebdriverIO service that automates the management of Selenium Standalone server during test execution. This service simplifies test setup by automatically handling the installation, configuration, and lifecycle of the Selenium server and browser drivers without requiring separate driver services.
npm install @wdio/selenium-standalone-service --save-devimport SeleniumStandaloneService, { launcher } from "@wdio/selenium-standalone-service";
import type { SeleniumStandaloneOptions } from "@wdio/selenium-standalone-service";
import { getFilePath, hasCapsWithSupportedBrowser } from "@wdio/selenium-standalone-service";For CommonJS:
const SeleniumStandaloneService = require("@wdio/selenium-standalone-service").default;
const { launcher, getFilePath, hasCapsWithSupportedBrowser } = require("@wdio/selenium-standalone-service");// WebdriverIO configuration (wdio.conf.js)
export const config = {
// ... other config
outputDir: "./logs", // Logs will be written here
services: [
["selenium-standalone", {
drivers: {
chrome: true,
firefox: "0.33.0"
}
}]
],
capabilities: [{
browserName: "chrome"
}]
};The service provides automated Selenium server lifecycle management through:
SeleniumStandaloneService class for WebdriverIO compatibilitySeleniumStandaloneLauncher handles server installation, startup, and teardownMain service class exported as default for WebdriverIO service integration.
/**
* WebdriverIO service class for Selenium Standalone integration
*/
export default class SeleniumStandaloneService {}
/**
* Launcher class for handling Selenium server lifecycle
*/
export const launcher: typeof SeleniumStandaloneLauncher;
/**
* All types and interfaces from the types module
*/
export * from './types';Core launcher class that manages Selenium server installation, startup, and teardown.
/**
* Launcher class for managing Selenium Standalone server lifecycle
*/
class SeleniumStandaloneLauncher {
constructor(
options: SeleniumStandaloneOptions,
capabilities: Capabilities.RemoteCapabilities,
config: Omit<Options.Testrunner, 'capabilities'>
);
/**
* Lifecycle hook called before test execution starts
* Installs drivers, starts Selenium server, configures capabilities
*/
async onPrepare(config: Options.Testrunner): Promise<void>;
/**
* Lifecycle hook called after test execution completes
* Stops the Selenium server process
*/
onComplete(): void;
/** Selenium start arguments */
args: SeleniumStartArgs;
/** Selenium install arguments */
installArgs: SeleniumInstallArgs;
/** Whether to skip selenium installation */
skipSeleniumInstall: boolean;
/** Watch mode flag */
watchMode: boolean;
/** Running Selenium process reference */
process: SeleniumStandalone.ChildProcess;
/** Browser driver versions for simplified mode */
drivers?: {
chrome?: string;
firefox?: string;
chromiumedge?: string;
ie?: string;
edge?: string;
};
}Usage Example:
// The launcher is typically not used directly, but through WebdriverIO service configuration
const launcher = new SeleniumStandaloneLauncher(
{ drivers: { chrome: true } },
[{ browserName: "chrome" }],
{ outputDir: "./logs" }
);
await launcher.onPrepare({ watch: false } as any);
// Selenium server is now running and capabilities are configured
launcher.onComplete();
// Selenium server is stoppedService configuration interface for customizing Selenium server behavior.
/**
* Configuration options for the Selenium Standalone service
*/
interface SeleniumStandaloneOptions {
/** Path where Selenium server logs should be stored (Note: Implementation uses WebdriverIO outputDir instead) */
logs?: string;
/** Arguments passed directly to selenium-standalone install() */
installArgs?: Partial<InstallOpts>;
/** Arguments passed directly to selenium-standalone start() */
args?: Partial<StartOpts>;
/** Skip automatic selenium-standalone server installation */
skipSeleniumInstall?: boolean;
/** Simplified browser driver version configuration */
drivers?: {
chrome?: string | boolean;
firefox?: string | boolean;
chromiumedge?: string | boolean;
ie?: string | boolean;
edge?: string | boolean;
};
}Configuration Examples:
// Simplified mode - easy driver configuration
const simpleConfig: SeleniumStandaloneOptions = {
drivers: {
chrome: true, // Use default/latest version
firefox: "0.33.0", // Use specific version
chromiumedge: "latest" // Use latest version
}
};
// Advanced mode - full control over selenium-standalone options
const advancedConfig: SeleniumStandaloneOptions = {
skipSeleniumInstall: false,
installArgs: {
version: "4.0.0",
drivers: {
chrome: { version: "91.0.4472.101" }
}
},
args: {
seleniumArgs: ["-host", "127.0.0.1", "-port", "4444"]
}
};Core utility functions for file path resolution and capability validation.
/**
* Resolves the given path into an absolute path and appends the default filename as fallback when the provided path is a directory
* @param filePath - Relative file or directory path
* @param defaultFilename - Default file name when filePath is a directory
* @returns Absolute file path
*/
function getFilePath(filePath: string, defaultFilename: string): string;
/**
* Find whether a browser session could be supported by the selenium-standalone service
* @param capabilities - Capabilities used for the session
* @returns True if capabilities suggest a supported platform
*/
function hasCapsWithSupportedBrowser(capabilities: Capabilities.Capabilities): boolean;Usage Examples:
import { getFilePath, hasCapsWithSupportedBrowser } from "@wdio/selenium-standalone-service";
// Resolve file path for logs
const logPath = getFilePath("./logs", "selenium.log");
// Result: "/absolute/path/to/logs/selenium.log"
// Check if capabilities are supported
const isSupported = hasCapsWithSupportedBrowser({ browserName: "chrome" });
// Result: true
const isUnsupported = hasCapsWithSupportedBrowser({ browserName: "opera" });
// Result: falseKey constants used by the service.
/** Default connection configuration for local Selenium server */
const DEFAULT_CONNECTION: {
protocol: 'http';
hostname: 'localhost';
port: 4444;
path: '/wd/hub';
};
/** Default log filename: 'wdio-selenium-standalone.log' */
const DEFAULT_LOG_FILENAME: 'wdio-selenium-standalone.log';
/** List of browser names supported by the service */
const SUPPORTED_CAPABILITIES: [
'chrome',
'googlechrome',
'firefox',
'edge',
'msedge',
'microsoftedge',
'microsoft edge',
'safari',
'webkit'
];/** Arguments for selenium-standalone start() method */
type SeleniumStartArgs = Partial<import('selenium-standalone').StartOpts>;
/** Arguments for selenium-standalone install() method */
type SeleniumInstallArgs = Partial<import('selenium-standalone').InstallOpts>;
/** Browser driver configuration for simplified mode */
type BrowserDrivers = {
chrome?: string | boolean;
firefox?: string | boolean;
chromiumedge?: string | boolean;
ie?: string | boolean;
edge?: string | boolean;
};
/** External WebdriverIO types */
type Capabilities = import('@wdio/types').Capabilities;
type Options = import('@wdio/types').Options;
type Services = import('@wdio/types').Services;
/** External selenium-standalone types */
type InstallOpts = import('selenium-standalone').InstallOpts;
type StartOpts = import('selenium-standalone').StartOpts;
type ChildProcess = import('selenium-standalone').ChildProcess;declare global {
namespace WebdriverIO {
/**
* Extended service options interface
* Note: 'args' property is omitted due to conflicts with Appium service
*/
interface ServiceOption extends Omit<SeleniumStandaloneOptions, 'args'> {}
}
}The service handles Selenium-related errors by:
@wdio/loggerprocess.exit(1) on critical installation/startup failuresCommon Error Scenarios: