CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-wdio--reporter

A WebdriverIO utility to help reporting all events with extensible base class for custom reporters

Pending
Overview
Eval results
Files

utilities.mddocs/

Utility Functions

The WDIO Reporter package provides a utility function for browser detection that is part of the public API.

Capabilities

Browser Detection

Function to extract browser name from WebDriver capabilities object.

/**
 * Returns the browser name from WebDriver capabilities
 * Supports both desktop browsers and mobile apps
 * @param caps - WebdriverIO Capabilities object
 * @returns Browser name or app identifier
 */
function getBrowserName(caps: WebdriverIO.Capabilities): string;

Usage Example:

import { getBrowserName } from "@wdio/reporter";

export class BrowserReporter extends WDIOReporter {
  onRunnerStart(runnerStats: RunnerStats) {
    const browserName = getBrowserName(runnerStats.capabilities);
    console.log(`Testing on: ${browserName}`);
    this.write(`=== Browser: ${browserName} ===\n`);
  }
}

// For mobile capabilities
const mobileCaps = {
  platformName: 'iOS',
  'appium:deviceName': 'iPhone 12',
  'appium:app': '/path/to/MyApp.app'
};
console.log(getBrowserName(mobileCaps)); // "MyApp.app"

// For desktop capabilities  
const desktopCaps = {
  browserName: 'chrome',
  browserVersion: '95.0'
};
console.log(getBrowserName(desktopCaps)); // "chrome"

The function handles both desktop browser capabilities and mobile app capabilities:

  • Desktop browsers: Returns browserName or browser property
  • Mobile apps: Extracts app name from various app-related properties:
    • appium:bundleId (iOS app bundle identifier)
    • appium:appPackage (Android package name)
    • appium:appActivity (Android activity name)
    • appium:app or app (app file path - returns basename)

Internal Utilities

The WDIO Reporter also uses several internal utility functions that are not part of the public API but are used internally for formatting, color output, and error processing:

  • sanitizeString() - Sanitizes strings for safe filenames
  • sanitizeCaps() - Formats capabilities into sanitized strings
  • color() - Applies ANSI color codes to content
  • colorLines() - Colors multi-line strings
  • pad() - Pads strings for alignment
  • getErrorsFromEvent() - Extracts errors from framework events
  • transformCommandScript() - Transforms WebDriver scripts for display

These utilities are used internally by the WDIOReporter class but are not exported as part of the public API. Custom reporters should use the provided event handler methods and statistics objects rather than accessing these internal utilities directly.

Install with Tessl CLI

npx tessl i tessl/npm-wdio--reporter

docs

events.md

index.md

reporter-base.md

statistics.md

utilities.md

tile.json