or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-wdio--selenium-standalone-service

A WebdriverIO service to start & stop Selenium Standalone

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@wdio/selenium-standalone-service@7.40.x

To install, run

npx @tessl/cli install tessl/npm-wdio--selenium-standalone-service@7.40.0

index.mddocs/

WebdriverIO Selenium Standalone Service

A 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.

Package Information

  • Package Name: @wdio/selenium-standalone-service
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @wdio/selenium-standalone-service --save-dev

Core Imports

import 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");

Basic Usage

// 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"
  }]
};

Architecture

The service provides automated Selenium server lifecycle management through:

  • Service Class: Empty SeleniumStandaloneService class for WebdriverIO compatibility
  • Launcher Implementation: SeleniumStandaloneLauncher handles server installation, startup, and teardown
  • Configuration Modes: Simplified driver configuration and advanced selenium-standalone integration
  • Capability Integration: Automatic capability configuration for local Selenium connection
  • Lifecycle Management: Integration with WebdriverIO's onPrepare/onComplete hooks

Capabilities

Service Configuration

Main 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';

Selenium Server Management

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 stopped

Configuration Options

Service 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"]
  }
};

Utility Functions

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: false

Constants

Key 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'
];

Type Definitions

/** 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;

Global Type Extensions

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'> {}
  }
}

Error Handling

The service handles Selenium-related errors by:

  • Logging errors through @wdio/logger
  • Calling process.exit(1) on critical installation/startup failures
  • Gracefully stopping the Selenium process during cleanup
  • Supporting both watch mode and standard execution modes

Common Error Scenarios:

  • Selenium installation failures (network issues, permissions)
  • Port conflicts when starting Selenium server
  • Driver installation failures for specific browser versions
  • Process cleanup issues during test interruption