@currents/playwright
Setup and usage instructions for Playwright integration with Currents Dashboard
Requirements
NodeJS 14.0.0+
Playwright 1.22.2+
Setup
Install @currents/playwright package
@currents/playwright packagenpm i -D @currents/playwrightUpdate playwright.config.js|ts
playwright.config.js|tsCreating a new organization and a project at https://app.currents.dev, you'll see on-screen instructions with your newly created Project ID and Record Key.
Enabled traces, videos and screenshots in
playwright.config.js|ts
use: {
// ...
trace: "on",
video: "on",
screenshot: "on",
}Using @currents/playwright
Choose the preferred usage method for @currents/playwright
pwcCLI command - runsplaywrightwith a predefined configuration.Alternatively, you can add
@currents/playwrightreporter toplaywright.config.ts
pwc CLI command
pwc CLI commandRun pwc to create your first Playwright run in Currents dashboard.
npx pwc --key RECORD_KEY --project-id PROJECT_ID --ci-build-id hello-currentsSet the Record Key, and Project ID obtained from Currents dashboard.
Set
--ci-build-idto a unique value for local testing. Learn more about CI Build ID for CI runs.
@currents/playwright reporter
@currents/playwright reporterAlternatively, you can manually add the reporter to Playwright configuration and keep using playwright test CLI command.
// playwright.config.ts
import { defineConfig, devices, PlaywrightTestConfig } from "@playwright/test";
import { CurrentsConfig, currentsReporter } from "@currents/playwright";
const currentsConfig: CurrentsConfig = {
ciBuildId: "ci-build-id", // 📖 https://currents.dev/readme/guides/ci-build-id
recordKey: "secret record key", // 📖 https://currents.dev/readme/guides/record-key
projectId: "project id", // get one at https://app.currents.dev
};
export default defineConfig({
// ...
reporter: [currentsReporter(currentsConfig)], // 👈🏻 add Currents reporter
})You can provide the required configuration as a parameter of currentsReporter function or as environment variables.
CURRENTS_PROJECT_ID=PROJECT_ID \ // the projectId from https://app.currents.dev
CURRENTS_RECORD_KEY=RECORD_KEY \ // the record key from https://app.currents.dev
CURRENTS_CI_BUILD_ID=hello-currents \ // the CI build ID
CURRENTS_TAG=tagA,tagB \
npx playwright testcmd /V /C "set CURRENTS_PROJECT_ID=PROJECT_ID // the projectId from https://app.currents.dev
&& set CURRENTS_RECORD_KEY=RECORD_KEY // the record key from https://app.currents.dev
&& set CURRENTS_CI_BUILD_ID=hello-currents // CI build id
&& set CURRENTS_TAG=tagA,tagB // tags for the created run
&& npx playwright test"With the reporter configured, you can run npx playwright test to start sending the results to Currents dashboard. Learn more about CI Build ID.
Configuring @currents/playwright
@currents/playwright accepts configuration from the following sources:
environment variables, e.g.
CURRENTS_TAG=tagA,tagBoptions of
pwcCLI command, e.g.npx pwc ---tag tagA --tag tagBreading
currentsReporterJS configuration object, e.g.reporters: [currentsReporter(options)]
The following configuration options are available:
--ci-build-idthe unique identifier for a run.
Environment variable:
CURRENTS_CI_BUILD_IDJS configuration key:
ciBuildId?: string
-k, --keyyour secret Record Key obtained from Currents.
Environment variable:
CURRENTS_RECORD_KEYJS configuration key:
recordKey: string
-p, --project-idthe project ID for results reporting obtained from Currents.
Environment variable:
CURRENTS_PROJECT_IDJS configuration key:
recordKey: string
-t, --tagcomma-separated tag(s) for recorded runs in Currents.
Environment variable:
CURRENTS_TAGJS configuration key:
tag?: string[]Released in version:
0.7.0
--pwc-remove-title-tagsremove tags from test names in Currents, e.g.
Test name @smokebecomesTest namein the dashboard (default: false). See Playwright Tags.Environment variable: n/a
JS configuration key:
removeTitleTags?: boolean = falseReleased in version:
0.10.0
--pwc-disable-title-tagsdisable parsing tags from test title, e.g.
Test name @smokewould not have tagsmokein the dashboard (default: false). See Playwright Tags.Environment variable:
CURRENTS_DISABLE_TITLE_TAGSJS configuration key:
disableTitleTags?: boolean = falseReleased in version:
0.11.0
--pwc-cancel-after-failures <number | false>abort the cloud run after the specified number of failed tests detected. Overrides the default Currents Project settings. If set, must be a positive integer or
falseto override automatic cancellations and project's Fail Fast Strategy. Also, see Canceling Runs andFail Fast StrategyEnvironment variable:
CURRENTS_CANCEL_AFTER_FAILURESJS configuration key:
cancelAfterFailures?: number | boolean = undefinedReleased in version:
0.11.0
--pwc-debug [boolean | "remote" | "full"]enable collecting debug logs for the reporter (default: false).
truewill print the debug logs to stdoutremotewill upload the debug logs to Currents servers.fullwill print the logs to stdout and also upload to Currents.
Environment variable:
CURRENTS_DEBUG=true | "remote" | "full"JS configuration key:
debug?: boolean | "remote" | "full" = falseReleased in version:
0.11.3
--pwc-output-file <path>file path for run summary output in JSON format. The summary data TypeScript type definition is available:
import { ExecutionJSONSummary } from '@currents/playwright'Environment variable:
CURRENTS_OUTPUT_FILE=/path/to/file.jsonJS configuration key:
outputFile?: stringReleased in version:
1.2.0
-V, --versionshow package version-h, --helpshowpwchelp
Overriding Configuration
Certain configuration values can have multiple sources, e.g. CLI fag and environment variables. Configuration values will resolve as follows:
first, the environment variable, if exists, otherwise
the corresponding CLI flag if exists, otherwise
currentsReporterJS configuration object, otherwisethe default value, otherwise
throw if the configuration is mandatory
Examples
Run all tests in the current directory:
pwc --key <record-key> --project-id <id> --ci-build-id <build-id> Run only tests filtered by the tag "@smoke":
pwc --key <record-key> --project-id <id> --ci-build-id <build-id> --grep smokeRun playwright tests and add tags "tagA", "tagB" to the recorded run:
pwc --key <record-key> --project-id <id> --ci-build-id <build-id> --tag tagA --tag tagBProvide
playwrightarguments and flags:
pwc --key <record-key> --project-id <id> --ci-build-id <build-id> -- --workers 2 --timeout 10000 --shard 1/2CI Examples
Check out the example repositories that showcase running Playwright tests on popular CI providers and recording the results to Currents:
Explore how to speed up CI Playwright runs by running enabling Playwright Parallelization.
Good To Know
Screenshots
By default, Playwright only captures screenshots at the end of a test, according to the provided screenshot option. Manually created screenshots are hidden by default and won't be attached to any test.
To send screenshots to Currents, they have to be attached to the test. For example, you can attach a screenshot to a test like this
const { test, expect } = require("@playwright/test");
test("basic test", async ({ page }, testInfo) => {
await page.goto("<https://playwright.dev>");
const screenshot = await page.screenshot();
await testInfo.attach("screenshot", {
body: screenshot,
contentType: "image/png",
});
});For more information see the Playwright test info attachment documentation.
Limitations
Rerunning with the same CI build ID would generate a warning and new results would not be uploaded. Please use a new CI build ID.
Last updated
Was this helpful?