What are Fixtures?

Fixtures are reusable pieces of setup and teardown code that runs before and after test execution. They help you prepare test environments and allow you to add functionality that is custom to your needs.

For detailed docs you can refer to Playwright Documentation.

Implementing Fixtures

inspecter-tests/fixtures.ts
import { Fixtures, TestFixtures, WorkerFixtures } from 'inspecter/core'

export interface E2ETestFixtures extends TestFixtures, WorkerFixtures {
  testFixtureExample: number[]
}

export interface E2EWorkerFixtures extends WorkerFixtures {
  workerFixtureExample: string
}

export const fixtures: Fixtures<E2ETestFixtures, E2EWorkerFixtures> = {
  testFixtureExample: [
    async ({}, use) => {
      // Create data in staging before test started
      const data = [1, 2, 3]

      await use(data)

      // Delete data after test finished
    },
    { scope: 'test' },
  ],
  workerFixtureExample: [
    async ({}, use) => {
      // Create data in staging before worker started
      const data = 'staging data'

      await use(data)

      // Delete data after worker finished
    },
    { scope: 'worker' },
  ],
}

Built-in Fixtures

Inspecter provides several built-in fixtures:

  • page: Playwright page object for browser automation
  • context: Browser context for managing cookies and storage
  • request: HTTP request context for API calls

How to use

You can select fixtures in the UI before creating a test or change them in an existing test script.