# @currents/playwright

## Requirements

* NodeJS 14.0.0+
* Playwright 1.22.2+

{% hint style="warning" %}
**Playwright 1.60.0+** requires `@currents/playwright` **2.0.0+**. See [Compatibility Guide](/resources/reporters/currents-playwright/compatibility.md).
{% endhint %}

***

## Setup

Creating 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.**

### Install `@currents/playwright`

```bash
npm i -D @currents/playwright
```

### Create `currents.config.ts`

Create `currents.config.(m|j|t)s` configuration file.

* Set the **Record Key**, and **Project ID** obtained from Currents dashboard.
* Learn more about [CI Build ID](/guides/parallelization-guide/ci-build-id.md).

```typescript
import { CurrentsConfig } from "@currents/playwright";

const config: CurrentsConfig = {
  recordKey: process.env.CURRENTS_RECORD_KEY || throw new Error("oh no!"),
  projectId: process.env.CURRENTS_PROJECT_ID
};

export default config;
```

### Update `playwright.config.js|ts`

Enabled traces, videos and screenshots in `playwright.config.js|ts`

```javascript
use: {
    // ...
    trace: "on",
    video: "on",
    screenshot: "on",
}
```

***

## Usage

Choose the preferred usage method. See details below.

* `pwc` command-line executable.
  * Run `pwc test` instead of `playwright test`
  * `pwc` automatically configures Playwright to work with Currents
  * Keep Currents configuration in `currents.config.ts`
* Manually add Currents Reporter.
  * Explicitly add Currents reporter to `playwright.config.ts`
  * Run `playwright test` as usual
  * Keep Currents configuration in `currents.config.ts`
* `pwc-p` command-line executable for orchestration.
  * Run `pwc-p run` to orchestrate tests across CI machines
  * Run `pwc-p discover` when filtering the suite (`--grep`, `--last-failed`, `--project`, spec paths)
  * Required to enable [Playwright Parallelization](/guides/ci-optimization/playwright-parallelization.md#playwright-orchestration)
  * See [Orchestration Setup](/guides/ci-optimization/playwright-orchestration.md) and [pwc-p (orchestration)](/resources/reporters/currents-playwright/pwc-p.md)

### `pwc` command-line executable

```bash
npx pwc --key RECORD_KEY --project-id PROJECT_ID --ci-build-id hello-currents
```

* `pwc` reads configuration from `currents.config.ts`
* Run `pwc` to start recording Playwright runs to Currents.
* Learn more about [CI Build ID](/guides/parallelization-guide/ci-build-id.md).
* See [pwc](/resources/reporters/currents-playwright/pwc.md) reference documentation.

{% hint style="info" %}
Using `pwc` command overrides the reporters configured in `playwright.config.ts` — you can specify additional reporters using `--reporter` flag. Alternatively, you can explicitly add the Currents reporter to `playwright.config.ts` and use `playwright test` as usual.
{% endhint %}

### `pwc-p` command-line executable

Use `pwc-p run` to orchestrate the full suite. When applying Playwright filters, run `pwc-p discover` first and pass the same discovery file to `pwc-p run`.

**Full suite (discovery optional):**

```bash
npx pwc-p run --key <record-key> --project-id <project-id> --ci-build-id <ci-build-id>
```

**Filtered tests (discovery required):**

```bash
npx pwc-p discover --pwc-discovery-file tests.txt --grep @smoke
npx pwc-p run --key <record-key> --project-id <project-id> --ci-build-id <ci-build-id> --pwc-discovery-file tests.txt
```

* `pwc-p run` reads configuration from `currents.config.ts`
* Playwright filter flags belong on `discover`; runtime flags (`-j`, `--timeout`) belong on `run`

### Manually Add Currents Reporter

You can manually add the Currents reporter to `playwright.config.ts` and use `playwright test` as usual.

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

export default defineConfig<CurrentsFixtures, CurrentsWorkerFixtures>({
  // ...
  reporter: [currentsReporter()], // 👈🏻 add Currents reporter
});
```

* The reporter reads the configuration from `currents.config.ts` file. See additional configuration options [#configuration](#configuration "mention").
* Run `npx playwright test` to start sending the results to Currents dashboard.
* Learn more about [CI Build ID](/guides/parallelization-guide/ci-build-id.md).

***

## Configuration

Numerous configuration options are available. See [Configuration](/resources/reporters/currents-playwright/configuration.md).

***

## Fixtures

The package also provides additional fixtures for Playwright that support various features:

* [Code Coverage for Playwright](/guides/coverage/code-coverage-for-playwright.md)
* [Currents Actions](/guides/currents-actions.md)

{% content-ref url="/pages/2LIiBq2uzYUhl3ZK2ZOp" %}
[Playwright Fixtures](/resources/reporters/currents-playwright/playwright-fixtures.md)
{% endcontent-ref %}

***

## Examples

* Run all tests in the current directory:

```bash
pwc --key <record-key> --project-id <id>
```

* Run orchestration for all tests in the current directory:

```bash
pwc-p run --key <record-key> --project-id <id> --ci-build-id <build-id>
```

* Run orchestration for tests filtered by the tag "@smoke":

```bash
pwc-p discover --pwc-discovery-file tests.txt --grep @smoke
pwc-p run --key <record-key> --project-id <id> --ci-build-id <build-id> --pwc-discovery-file tests.txt
```

* Run only tests filtered by the tag "@smoke" (non-orchestrated):

```bash
pwc --key <record-key> --project-id <id> --grep smoke
```

* Run playwright tests and add tags "tagA", "tagB" to the recorded run:

```bash
pwc --key <record-key> --project-id <id> --tag tagA --tag tagB
```

* Provide `playwright` arguments and flags:

```bash
pwc --key <record-key> --project-id <id> -- --workers 2 --timeout 10000 --shard 1/2
```

## CI Examples

Check out the example repositories that showcase running Playwright tests on popular CI providers and recording the results to Currents:

* [GitHub Actions](/getting-started/ci-setup/github-actions.md)
* [GitLab](/getting-started/ci-setup/gitlab.md)
* [Jenkins](/getting-started/ci-setup/jenkins.md)
* [CircleCI](/getting-started/ci-setup/playwright-circleci.md)
* [AWS Code Build](/getting-started/ci-setup/playwright-aws-code-build.md)
* [Azure DevOps](/getting-started/ci-setup/playwright-azure-devops.md)

Explore how to speed up CI Playwright runs by enabling [Playwright Parallelization](/guides/ci-optimization/playwright-parallelization.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.currents.dev/resources/reporters/currents-playwright.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
