When running API tests, how do you know if your test suite actually covers all the endpoints defined in your OpenAPI specification? wdio-openapi-service answers this by tracking every API request during your WebdriverIO test runs and matching them against your OpenAPI/Swagger spec.

Why API Coverage Matters

You might have hundreds of tests passing, but if they only exercise 60% of your API surface, you have blind spots. This service gives you a clear picture:

FeatureDescription
Complete TrackingTracks all API requests made during test runs
Spec MatchingMatches requests against OpenAPI 3.0 and Swagger 2.0
Method BreakdownCoverage by HTTP method (GET, POST, PUT, DELETE)
Path NormalizationConverts /users/123 to /users/{id} automatically
CI/CD ReadyWorks with GitHub Actions, Jenkins, CircleCI

Installation

npm install --save-dev wdio-openapi-service

Quick Start

Step 1: Add the Service

Add the service to your wdio.conf.ts:

export const config = {
  services: [
    ['openapi', {
      openApiPath: './openapi.yaml',
      outputPath: './reports/api-coverage.json'
    }]
  ]
}

Step 2: Use the API Client

import { apiClient } from 'wdio-openapi-service'

describe('API Tests', () => {
  it('should retrieve user data', async () => {
    const response = await apiClient.get('https://api.example.com/users/1')
    expect(response.status).toBe(200)
  })
})

Step 3: Check Your Coverage Report

After running tests, check ./reports/api-coverage.json:

{
  "summary": {
    "totalEndpoints": 7,
    "testedEndpoints": 5,
    "untestedEndpoints": 2,
    "coveragePercentage": 71.43
  },
  "methodCoverage": {
    "GET": {"total": 4, "tested": 3, "percentage": 75},
    "POST": {"total": 1, "tested": 1, "percentage": 100},
    "PUT": {"total": 1, "tested": 1, "percentage": 100},
    "DELETE": {"total": 1, "tested": 0, "percentage": 0}
  }
}

Configuration Options

OptionTypeDefaultDescription
openApiPathstringAuto-detectedPath to your OpenAPI spec file
outputPathstring./api-coverage-report.jsonWhere to save the report
logLevelstringinfoLogging level
enableDynamicPatternLearningbooleantrueLearn patterns from requests
endpointPatternFilestring-Custom pattern rules file

Path Normalization

Path normalization converts dynamic paths like /users/123 to template paths like /users/{id}. This works through three mechanisms:

  • OpenAPI-based — Paths from your spec are used as templates
  • Custom patterns — Define regex patterns for specific endpoints
  • Dynamic learning — The service auto-detects patterns from your API calls

Custom Pattern Example

services: [
  ['openapi', {
    openApiPath: './openapi.yaml',
    customPatterns: [
      {
        pattern: new RegExp('/users/\\d+'),
        template: '/users/{id}',
        priority: 100
      }
    ]
  }]
]

CI Integration

# GitHub Actions
jobs:
  api-coverage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
      - run: npm ci
      - run: npx wdio run wdio.conf.ts
      - uses: actions/upload-artifact@v4
        with:
          name: api-coverage
          path: ./reports/api-coverage.json

For the full documentation, visit the GitHub repo.


Have questions about API coverage tracking? Feel free to reach out or open an issue on GitHub.