NX
Running Playwright tests with NX
Running Playwright tests in an 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.
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:
executorproperty has the valuenx:run-commands.A
commandproperty is added withinoptions. This executesnpx pwc-p runfor orchestration. See Orchestration Setup.Reporter config in
playwright.configfile is not neededOrchestration runs the full suite by default — use
or8n-discoverfirst to filter tests
To locally execute orchestration nx project:
Or with discovery (for filtered runs):
Last updated
Was this helpful?