A WebdriverIO utility to help reporting all events with extensible base class for custom reporters
—
The WDIO Reporter package provides a utility function for browser detection that is part of the public API.
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:
browserName or browser propertyappium:bundleId (iOS app bundle identifier)appium:appPackage (Android package name)appium:appActivity (Android activity name)appium:app or app (app file path - returns basename)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 filenamessanitizeCaps() - Formats capabilities into sanitized stringscolor() - Applies ANSI color codes to contentcolorLines() - Colors multi-line stringspad() - Pads strings for alignmentgetErrorsFromEvent() - Extracts errors from framework eventstransformCommandScript() - Transforms WebDriver scripts for displayThese 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