or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

events.mdindex.mdreporter-base.mdstatistics.mdutilities.md

utilities.mddocs/

0

# Utility Functions

1

2

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

3

4

## Capabilities

5

6

### Browser Detection

7

8

Function to extract browser name from WebDriver capabilities object.

9

10

```typescript { .api }

11

/**

12

* Returns the browser name from WebDriver capabilities

13

* Supports both desktop browsers and mobile apps

14

* @param caps - WebdriverIO Capabilities object

15

* @returns Browser name or app identifier

16

*/

17

function getBrowserName(caps: WebdriverIO.Capabilities): string;

18

```

19

20

**Usage Example:**

21

22

```typescript

23

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

24

25

export class BrowserReporter extends WDIOReporter {

26

onRunnerStart(runnerStats: RunnerStats) {

27

const browserName = getBrowserName(runnerStats.capabilities);

28

console.log(`Testing on: ${browserName}`);

29

this.write(`=== Browser: ${browserName} ===\n`);

30

}

31

}

32

33

// For mobile capabilities

34

const mobileCaps = {

35

platformName: 'iOS',

36

'appium:deviceName': 'iPhone 12',

37

'appium:app': '/path/to/MyApp.app'

38

};

39

console.log(getBrowserName(mobileCaps)); // "MyApp.app"

40

41

// For desktop capabilities

42

const desktopCaps = {

43

browserName: 'chrome',

44

browserVersion: '95.0'

45

};

46

console.log(getBrowserName(desktopCaps)); // "chrome"

47

```

48

49

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

50

51

- **Desktop browsers**: Returns `browserName` or `browser` property

52

- **Mobile apps**: Extracts app name from various app-related properties:

53

- `appium:bundleId` (iOS app bundle identifier)

54

- `appium:appPackage` (Android package name)

55

- `appium:appActivity` (Android activity name)

56

- `appium:app` or `app` (app file path - returns basename)

57

58

## Internal Utilities

59

60

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:

61

62

- `sanitizeString()` - Sanitizes strings for safe filenames

63

- `sanitizeCaps()` - Formats capabilities into sanitized strings

64

- `color()` - Applies ANSI color codes to content

65

- `colorLines()` - Colors multi-line strings

66

- `pad()` - Pads strings for alignment

67

- `getErrorsFromEvent()` - Extracts errors from framework events

68

- `transformCommandScript()` - Transforms WebDriver scripts for display

69

70

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.