CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-webdriverio

Next-gen browser and mobile automation test framework for Node.js

Pending
Overview
Eval results
Files

session-management.mddocs/

Session Management

Core session creation and management functionality for initializing WebDriver connections and managing browser instances.

Capabilities

Remote Session Creation

Creates a new WebdriverIO session with specified capabilities and configuration.

/**
 * Creates a new WebdriverIO session
 * @param params - Configuration object including capabilities and WebDriver options
 * @param remoteModifier - Optional function to modify the remote instance
 * @returns Promise resolving to a Browser instance
 */
function remote(params: Capabilities.WebdriverIOConfig, remoteModifier?: Function): Promise<WebdriverIO.Browser>;

interface Capabilities.WebdriverIOConfig {
  capabilities: object;
  logLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent';
  connectionRetryTimeout?: number;
  connectionRetryCount?: number;
  automationProtocol?: 'webdriver' | 'devtools';
  baseUrl?: string;
  waitforTimeout?: number;
  waitforInterval?: number;
  region?: string;
  hostname?: string;
  port?: number;
  path?: string;
  protocol?: 'http' | 'https';
  user?: string;
  key?: string;
  services?: any[];
  reporters?: any[];
  framework?: string;
  mochaOpts?: object;
  jasmineOpts?: object;
  cucumberOpts?: object;
}

Usage Examples:

import { remote } from "webdriverio";

// Basic Chrome session
const browser = await remote({
  capabilities: {
    browserName: 'chrome'
  }
});

// Advanced configuration with custom options
const browser = await remote({
  capabilities: {
    browserName: 'firefox',
    'moz:firefoxOptions': {
      args: ['--headless']
    }
  },
  logLevel: 'debug',
  waitforTimeout: 10000,
  baseUrl: 'https://example.com'
});

// Mobile session using Appium
const driver = await remote({
  capabilities: {
    platformName: 'iOS',
    'appium:deviceName': 'iPhone Simulator',
    'appium:app': '/path/to/app.ipa'
  },
  hostname: 'localhost',
  port: 4723,
  path: '/wd/hub'
});

Session Attachment

Attaches to an existing WebDriver session using its session ID.

/**
 * Attaches to an existing WebDriver session
 * @param attachOptions - Options including session ID and protocol details
 * @returns Promise resolving to a Browser instance
 */
function attach(attachOptions: AttachOptions): Promise<WebdriverIO.Browser>;

interface AttachOptions {
  sessionId: string;
  isW3C?: boolean;
  commandTimeout?: number;
  hostname?: string;
  port?: number;
  path?: string;
  protocol?: 'http' | 'https';
}

Usage Examples:

import { attach } from "webdriverio";

// Attach to existing session
const browser = await attach({
  sessionId: '4f9e8e8a-7b1c-4d2e-9a5f-6c8d7e9f0a1b'
});

// Attach with custom endpoint
const browser = await attach({
  sessionId: '4f9e8e8a-7b1c-4d2e-9a5f-6c8d7e9f0a1b',
  hostname: 'selenium-hub.example.com',
  port: 4444,
  path: '/wd/hub'
});

Multi-Remote Sessions

Creates multiple remote sessions for parallel multi-browser testing scenarios.

/**
 * Creates multiple remote sessions for multi-browser testing
 * @param params - Configuration object mapping instance names to capabilities
 * @param options - Optional automation protocol specification
 * @returns Promise resolving to a MultiRemoteBrowser instance
 */
function multiremote(
  params: Capabilities.RequestedMultiremoteCapabilities, 
  options?: {automationProtocol?: string}
): Promise<WebdriverIO.MultiRemoteBrowser>;

interface Capabilities.RequestedMultiremoteCapabilities {
  [instanceName: string]: {
    capabilities: object;
    [key: string]: any;
  };
}

interface WebdriverIO.MultiRemoteBrowser {
  [instanceName: string]: WebdriverIO.Browser;
  sync(instanceNames?: string[]): Promise<void>;
  select(instanceName: string): WebdriverIO.Browser;
}

Usage Examples:

import { multiremote } from "webdriverio";

// Multi-browser testing setup
const matrix = await multiremote({
  chrome: {
    capabilities: {
      browserName: 'chrome'
    }
  },
  firefox: {
    capabilities: {
      browserName: 'firefox'
    }
  },
  safari: {
    capabilities: {
      browserName: 'safari'
    }
  }
});

// Navigate all browsers to the same page
await matrix.url('https://example.com');

// Interact with specific browsers
await matrix.chrome.$('#chrome-specific').click();
await matrix.firefox.$('#firefox-specific').click();

// Synchronize all browsers
await matrix.sync();

// Execute commands on all browsers in parallel
const titles = await matrix.getTitle();
console.log(titles); // { chrome: 'Title', firefox: 'Title', safari: 'Title' }

Session Configuration

Default configuration options and constants used throughout WebdriverIO.

const WDIO_DEFAULTS: {
  automationProtocol: 'webdriver';
  waitforTimeout: 3000;
  waitforInterval: 500;
  connectionRetryTimeout: 120000;
  connectionRetryCount: 3;
  logLevel: 'info';
  coloredLogs: true;
  deprecationWarnings: true;
  bail: 0;
  screenshotPath: './errorShots/';
  baseUrl: null;
  specs: [];
  suites: {};
  exclude: [];
  reporters: ['spec'];
  services: [];
  framework: 'mocha';
  mochaOpts: {
    timeout: 10000;
  };
  jasmineOpts: {
    defaultTimeoutInterval: 10000;
  };
  cucumberOpts: {
    timeout: 10000;
  };
};

Session Lifecycle

Methods for managing session state and lifecycle.

/**
 * Reload the WebDriver session, maintaining the same capabilities
 * @returns Promise that resolves when session is reloaded
 */
reloadSession(): Promise<void>;

/**
 * End the WebDriver session and close all associated windows
 * @returns Promise that resolves when session is closed
 */
deleteSession(): Promise<void>;

/**
 * Get the current session ID
 * @returns The session identifier string
 */
getSessionId(): string;

/**
 * Get the session capabilities
 * @returns Object containing the session capabilities
 */
getCapabilities(): object;

Error Handling

WebdriverIO-specific error classes for session management failures.

class SevereServiceError extends Error {
  name: 'SevereServiceError';
  message: string;
  stack?: string;
  
  constructor(message: string);
}

This error is thrown when critical service failures occur that prevent normal session operation, such as WebDriver server crashes or network connectivity issues that cannot be recovered from automatically.

Install with Tessl CLI

npx tessl i tessl/npm-webdriverio

docs

browser-control.md

dialog-handling.md

element-interaction.md

element-selection.md

index.md

mobile-automation.md

session-management.md

testing-utilities.md

tile.json