Currents Documentation
Currents.devGitHubChangelog
  • Getting Started
    • What is Currents?
    • Playwright
      • Playwright: Quick Start
      • Troubleshooting Playwright
    • Cypress
      • Your First Cypress Run
      • Integrating with Cypress
        • Compatibility
        • Alternative Cypress Binaries
      • Troubleshooting Cypress
    • Jest
      • Your First Jest Run
      • Detox + Jest
      • Troubleshooting Jest
    • Others
    • CI Setup
      • GitHub Actions
        • Cypress - GitHub Actions
        • Playwright - GitHub Actions
        • Jest - GitHub Actions
        • Node.js - GitHub Actions
        • Commit data for GitHub Actions
        • Custom Docker runners
        • Named Runners
      • GitLab
        • Cypress - GitLab CI/CD
        • Playwright - GitLab CI/CD
        • Custom Docker runners
      • Jenkins
        • Cypress - Jenkins
        • Playwright - Jenkins
      • CircleCI
        • Cypress - CircleCI
        • Playwright - CircleCI
      • Bitbucket
        • Cypress - Bitbucket Pipelines
      • Azure DevOps
        • Cypress - Azure DevOps
        • Playwright - Azure DevOps
      • AWS Code Build
        • Cypress - AWS Code Build
        • Playwright - AWS Code Build
      • NX
        • Playwright - NX
        • Cypress - NX
  • Guides
    • Record Key
    • CI Build ID
    • Reporting
      • Reporting Strategy
      • Reporting in CI
      • Step-Level Reporting
    • CI Optimization
      • Playwright Parallelization
      • Orchestration Setup
      • Fully Parallel Mode
      • Re-run Only Failed Tests
      • Cloud Spot Instances
      • Failing Fast
      • Load Balancing
    • Code Coverage
      • Code Coverage for Playwright
      • Code Coverage for Cypress
    • Currents Actions
      • Setup Currents Actions
      • Using Currents Actions
      • Reference
        • Conditions
        • Actions
    • Playwright Component Testing
    • Playwright Visual Testing
    • Playwright Annotations
    • Playwright Tags
    • MCP Server
  • Dashboard
    • Projects
      • Projects Summary view
      • Project Settings
      • Archive and Unarchive Projects
    • Runs
      • Run Status
      • Run Details
      • Commit Information
      • Tags
      • Run Timeouts
      • Canceling Runs
      • Deleting Runs
      • Run Progress
    • Tests
      • Spec File Status
      • Test Status
      • Flaky Tests
      • Test History
    • Test Suite Explorer
      • Test Explorer
        • Tests Performance
      • Spec Files Explorer
        • Spec Files Performance
      • Errors Explorer
  • Automated Reports
  • Insights and Analytics
  • Administration
    • Email Domain Based Access
    • SSO SAML2.0
      • SAML2.0 Configuration
      • SCIM User Provisioning
      • IdP-initiated Sessions
      • JumpCloud
        • JumpCloud User provisioning
      • Okta
        • Okta User provisioning
      • Troubleshooting SSO
    • Billing & Usage
  • Billing and Pricing
  • Resources
    • Reporters
      • cypress-cloud
        • Batched Orchestration
        • Migration to Cypress@13
      • @currents/cli
      • @currents/playwright
        • Configuration
        • pwc
        • pwc-p (orchestration)
        • Playwright Fixtures
      • @currents/jest
      • @currents/node-test-reporter
      • @currents/cmd
        • currents api
        • currents upload
        • currents cache
        • currents convert
      • Data Format Reference
    • Integrations
      • GitHub
        • GitHub App
        • GitHub OAuth
      • GitLab
      • Slack
      • Microsoft Teams
      • HTTP Webhooks
      • Bitbucket
    • API
      • Introduction
      • Authentication
      • API Keys
      • Errors
      • Pagination
      • API Resources
        • Instances
        • Runs
        • Projects
        • Spec Files
        • Test Signature
        • Test Results
    • Data Privacy
      • Access to Customer Data
      • Data Retention
      • Cloud Endpoints
    • Support
Powered by GitBook
On this page
  • Requirements
  • Overview
  • Setting up Currents Fixtures
  • Combine Currents fixtures with existing custom fixtures
  • Conditionally Enable Fixtures
  • Available Fixtures

Was this helpful?

  1. Resources
  2. Reporters
  3. @currents/playwright

Playwright Fixtures

Enhance Playwright functionality with Currents fixtures for Playwright

Previouspwc-p (orchestration)Next@currents/jest

Last updated 2 months ago

Was this helpful?

Requirements

  • Requires @currents/playwright 1.7.0+

Overview

is an important concept in Playwright ecosystem that allow augmenting and modifying the behaviour of Playwright tests.

Current integration with Playwright includes a several fixtures for enabling advanced Currents features like:

  • Code Coverage for Playwright

  • Currents Actions

Setting up Currents Fixtures

1

Create and export a new instance of test for adding fixtures

Create a new file in your repo in a location that can be imported from your tests. (Or if you are already using custom fixtures, follow your existing pattern).

import { test as baseTest } from '@playwright/test';
import { 
  CurrentsFixtures,
  CurrentsWorkerFixtures,
  fixtures
} from '@currents/playwright';

export const test = baseTest.extend<CurrentsFixtures, CurrentsWorkerFixtures>({
  ...fixtures.baseFixtures,
});

2

Add additional Currents feature fixtures

The baseFixtures are required for loading the currents config for the other Currents fixtures. You will also want to include any Currents fixture you plan on using. Here is and as an example:

currentsTest.ts
import { test as baseTest } from '@playwright/test';
import { 
  CurrentsFixtures,
  CurrentsWorkerFixtures,
  fixtures
} from '@currents/playwright';

export const test = baseTest.extend<CurrentsFixtures, CurrentsWorkerFixtures>({
  ...fixtures.baseFixtures,
  ...fixtures.coverageFixtures,
  ...fixtures.actionFixtures,
});

3

Optional: set fixture configuration

We pick up the configuration automatically from the currents.config.js|ts file - if you created the file you can skip this step. If you explicitly provide config to the Currents reporter in your playwright.config.ts you will also need to pass that same config to the fixture like this:

playwright.config.ts
import {
  currentsReporter,
  CurrentsWorkerFixtures,
  CurrentsFixtures,
} from "@currents/playwright";
import { devices, defineConfig } from "@playwright/test";

const config = defineConfig<CurrentsFixtures, CurrentsWorkerFixtures>({
    use: {
      // add the currents config here to be used in the fixture
      currentsConfigOptions: {
        ... insert your currents config here
      },
      // Optionally disable Currents fixtures. (defaults to enabled)
      // currentsFixturesEnabled: false
    }),
   ... other config
});

export default config;

4

Use the new implementation in your tests

Import the new test implementation and use it in your tests where you want to use the features provided by the fixtures (or Combine Currents fixtures with existing custom fixtures).

import { test } from './currentsTest';
import { expect } from "@playwight/test"


test('basic test', async ({ page }) => {
  await todoPage.addToDo('something nice');
  await expect(page.getByTestId('todo-title')).toContainText(['something nice']);
});

If you want to test that fixtures are loading, you can confirm that the currentsConfig is loaded by calling the fixture in one of the tests, and printing it’s result.

import { test } from './currentsTest';
import { expect } from "@playwight/test"


test('basic test', async ({ page, currentsConfig }) => {
  console.log(currentsConfig);
  await todoPage.addToDo('something nice');
  await expect(page.getByTestId('todo-title')).toContainText(['something nice']);
});

Combine Currents fixtures with existing custom fixtures

If you already have your own custom fixtures, you will want to use to combined fixtures from multiple modules. The merged result should be exported and used in your tests.

fixtures.ts
import { mergeTests } from '@playwright/test';
import { test as dbTest } from 'databaseTest';
import { test as currentsTest } from 'currentsTest';

export const test = mergeTests(currentsTest, dbTest);
test.spec.ts
import { test } from './fixtures';

test('passes', async ({ database, page, currentsConfig }) => {
  // use database and currentsConfig fixtures.
});

When combining the Currents fixtures with existing fixtures, it's often desirable to place the Currents fixtures first. This enables Currents to take actions even if a failure happened in your later fixtures.

Conditionally Enable Fixtures

After extending the test method, many Currents fixtures are enabled by default. If you wish to only conditionally enable them (such as only in CI) you can use the currentsFixturesEnabled property in your playwright.config.ts file.

playwright.config.ts
// ...
use: {
  ...
  currentsFixturesEnabled: !!process.env.CI,
},

Available Fixtures

baseFixtures
  • curentsConfigOptions

  • currentsConfig

  • gitInfo

Other Currents fixtures depend on these. They are loaded once per worker.

coverageFixtures
  • context

actionsFixtures

Available for in @currents/playwright v1.9.0+

See Currents Actions for details

See for details

Playwright custom fixtures
Currents Actions
Playwright's mergeTests helper
#code-coverage-for-playwright
Playwright coverage