Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Webdriverio Webdriverio Frameworks Types

From Leeroopedia
Knowledge Sources
Domains Type_Definitions, Test_Frameworks
Last Updated 2026-02-12 00:00 GMT

Overview

Type definitions for test framework entities including Mocha/Jasmine test structures and Cucumber-specific scenario, step, and tag interfaces.

Description

This module provides unified type definitions for test framework data structures used across WebdriverIO's framework adapters. The Suite and Test interfaces model Mocha/Jasmine test entities with properties like title, fullTitle, pending, and file. TestResult captures outcome data including pass/fail status, duration, and retry information. For Cucumber support, the module defines World, PickleResult, PickleStep, Tag, and Scenario interfaces that map to Cucumber's pickle-based execution model. These types serve as the common language between framework adapters and WebdriverIO's hook and reporter systems.

Usage

Use these types when implementing custom reporters that process test results, writing service hooks that react to test lifecycle events (e.g., beforeTest, afterTest), or building framework adapters. The Test and TestResult interfaces appear as parameters in many hook functions defined in the Services module. Cucumber-specific types are used by the Cucumber framework adapter and in Cucumber-specific hooks like beforeScenario and afterStep.

Code Reference

Source Location

Signature

export interface Suite {
    type: string
    title: string
    parent: string
    fullTitle: string
    pending: boolean
    file: string
    error?: any
    duration?: number
}

export interface Test extends Suite {
    fullName: string
    fn?: Function
    body?: string
    async?: number
    sync?: boolean
    timedOut?: boolean
    ctx: any
    description?: string       // Mocha flag
    _retriedTest?: any
    _currentRetry?: number
    _retries?: number
}

export interface TestRetries {
    limit: number
    attempts: number
}

export interface TestResult {
    error?: any
    result?: any
    passed: boolean
    duration: number
    retries: TestRetries
    exception: string
    status: string
}

export interface Results {
    finished: number
    passed: number
    failed: number
}

export interface World {
    pickle: { name?: string }
    result?: {
        duration: { seconds: number; nanos: number }
        status: 'UNKNOWN' | 'PASSED' | 'SKIPPED' | 'PENDING' | 'UNDEFINED' | 'AMBIGUOUS' | 'FAILED'
        message?: string
        willBeRetried: boolean
    }
}

export interface PickleResult {
    passed: boolean
    error?: string
    duration?: number
}

export interface PickleStep {
    id: string
    text: string
    astNodeIds: string[]
    keyword: 'Given ' | 'When ' | 'Then ' | 'And '
}

export interface Tag {
    name: string
    astNodeId: string
}

export interface Scenario {
    id: string
    uri: string
    name: string
    astNodeIds: string[]
    steps: PickleStep[]
    tags: Tag[]
}

Import

import type { Frameworks } from '@wdio/types'

// Access specific interfaces
type TestSuite = Frameworks.Suite
type TestCase = Frameworks.Test
type Result = Frameworks.TestResult
type CucumberScenario = Frameworks.Scenario
type CucumberStep = Frameworks.PickleStep
type CucumberWorld = Frameworks.World

I/O Contract

Key Type Members (Suite)
Name Type Required Description
type string Yes Type identifier for the suite
title string Yes Title of the test suite
parent string Yes Parent suite name
fullTitle string Yes Full hierarchical title
pending boolean Yes Whether suite is pending/skipped
file string Yes Source file path of the suite
duration number No Execution duration in milliseconds
Key Type Members (TestResult)
Name Type Required Description
passed boolean Yes Whether the test passed
duration number Yes Test duration in milliseconds
retries TestRetries Yes Retry limit and attempt count
exception string Yes Exception message if failed
status string Yes Test status string
error any No Error object if test failed
Dependent / Derived Types
Name Description Used By
Test Extends Suite with test-specific fields Hook parameters in beforeTest, afterTest
TestResult Test outcome data afterTest hook, reporters
Results Aggregate test run results onComplete hook
Scenario Cucumber scenario with steps and tags Cucumber framework adapter
World Cucumber World object with pickle and result Cucumber step definitions

Usage Examples

import type { Frameworks } from '@wdio/types'

// Use in afterTest hook
async function afterTest(
    test: Frameworks.Test,
    context: any,
    result: Frameworks.TestResult
) {
    if (!result.passed) {
        console.error(`FAILED: ${test.fullTitle} in ${test.file}`)
        console.error(`Error: ${result.exception}`)
        console.error(`Duration: ${result.duration}ms`)
        console.error(`Retries: ${result.retries.attempts}/${result.retries.limit}`)
    }
}

// Use in a custom reporter
function processSuite(suite: Frameworks.Suite) {
    if (suite.pending) {
        console.log(`Skipped suite: ${suite.fullTitle}`)
        return
    }
    console.log(`Suite: ${suite.fullTitle} (${suite.duration}ms)`)
}

// Aggregate results in onComplete
function onComplete(exitCode: number, config: any, caps: any, results: Frameworks.Results) {
    console.log(`Finished: ${results.finished}, Passed: ${results.passed}, Failed: ${results.failed}`)
}

// Cucumber scenario handling
function processScenario(scenario: Frameworks.Scenario) {
    const tags = scenario.tags.map(t => t.name).join(', ')
    console.log(`Scenario: ${scenario.name} [${tags}]`)
    for (const step of scenario.steps) {
        console.log(`  ${step.keyword}${step.text}`)
    }
}

// Cucumber World usage
function checkCucumberResult(world: Frameworks.World) {
    if (world.result?.status === 'FAILED') {
        console.error(`Scenario "${world.pickle.name}" failed: ${world.result.message}`)
    }
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment