Playwright - NX

Running Playwright tests with NX

Running cypress tests in NX project with Currents

Nx is a build system with monorepo support and powerful integrations. Playwright tests executions in Nx can be done by using @nx/playwright plugin.

This example repository showcases all the implementation described here.

To use the nx playwright plugin, Currents client must be set as reporter option in the playwright.config file.

Here a quick example:

import { nxE2EPreset } from '@nx/playwright/preset';
import { defineConfig, devices } from '@playwright/test';
import { CurrentsConfig, currentsReporter } from '@currents/playwright';

const currentsConfig: CurrentsConfig = {
  recordKey: process.env.CURRENTS_RECORD_KEY,
  projectId: process.env.CURRENTS_PROJECT_ID,
};

const nxConf = nxE2EPreset(__filename);
export default defineConfig({
  ...nxConf,
  reporter: [currentsReporter(currentsConfig)],
  ...
  ...
});

In order to execute the tests, our example project.json file includes the e2e target and Playwright plugin as executor property.

The command to execute the tests with Playwright is:

This will create a run execution in Currents reporting the tests results.

Using --last-failed flag

For executing only the failed tests according to a previous run, add the --last-failed flag to the execution command.

For a more detailed explanation on last failed CI setup, see here

Orchestration in a single project

It is possible to orchestrate the Playwright tests in a single nx project by using the same ci-build-id across multiple machines.

This is showcased in the e2e-03 nx project and the project.json file is slightly different than for the other projects.

Key differences with other nx projects in the example repository:

  • executor property has the value nx:run-commands.

  • A command property is added within options . This executes npx pwc-p which is the Currents orchestration command.

  • Reporter config in playwright.config file is not needed

To locally execute orchestration nx project:

This Github Action yaml file executes the Playwright tests distributed in three shards:

Last updated

Was this helpful?