# Re-run Only Failed Tests

Starting from version [1.44](https://playwright.dev/docs/release-notes?ref=playwrightsolutions.com#version-144) Playwright supports [running only the failed test from the last run](https://playwrightsolutions.com/how-to-run-failures-only-from-the-last-playwright-run/) using `--last-failed` CLI flag. For example:

```
playwright test --last-failed
```

{% hint style="info" %}
`@playwright/test@1.50+` has an improved support of `--last-failed` on CI, we recommend upgrading the package version accordingly.
{% endhint %}

<figure><img src="/files/Rmn7GrmtlB0LBbnFogT1" alt=""><figcaption><p>Rerunning Failed Only Playwright Tests</p></figcaption></figure>

While this feature works well for local environments, using it in CI with Playwright shards or Currents Orchestration is not straightforward.

We have created a set of tools that simplify rerunning only the failed Playwright tests in CI, including sharded parallel CI runs and runs created by Currents Orchestration.

{% hint style="warning" %}
Tests that randomly fail and then pass without any change are considered flaky (see [Flaky Tests](/dashboard/tests/flaky-tests.md)). Even if tests pass after a rerun, it is recommended to explore the failures and eliminate the flakiness.
{% endhint %}

### Re-run Only Failed Tests: Playwright Shards

The suggested templates do not require maintaining complex CI configurations and scripts - they are compatible with popular CI providers and can be used even without Currents reporter.

<details>

<summary>GitHub Actions</summary>

See our step-by-step guide [Re-run Only Failed Tests](/getting-started/ci-setup/github-actions/re-run-failed-only-tests.md)

</details>

<details>

<summary>GitLab CI</summary>

See our step-by-step guide to [Setting up retries of failed job with GitLab CI](/getting-started/ci-setup/gitlab/playwright-gitlab-ci-cd.md#playwright-sharding)

</details>

<details>

<summary>Jenkins Pipeline</summary>

See our step-by-step guide to [Setting up retries of failed job with Jenkins Pipeline](broken://pages/4LoOSvPTa9mW7D6zFRyO#using-last-failed-flag-with-shards-and-orchestration)

</details>

### Re-run Failed Playwright Tests: Currents Orchestration

{% hint style="info" %}
When rerunning failed orchestrated runs, select "Rerun All Jobs" instead of "Rerun Failed Only"
{% endhint %}

Orchestrated runs are conceptually different from the native playwright sharding. Currents assigns the tests dynamically to **all the available machines -** i.e. the more machines are available, the better (also, there's no need to provide the overall number of CI machines in advance).

<figure><img src="/files/EH56Ma2yC20BHMChNq7e" alt=""><figcaption><p>Rerunning Failed Only Playwright Tests using Currents Orchestration</p></figcaption></figure>

That's why when rerunning failed orchestrated CI runs, you'd select "Rerun All Jobs" instead of "Rerun Failed Only":

* The CI provider will spin up all the containers
* Currents will dynamically assign the failed tests to all the available containers
* More available containers will run the tests in parallel faster

<details>

<summary>GitHub Actions</summary>

See our step-by-step guide [Re-run Only Failed Tests](/getting-started/ci-setup/github-actions/re-run-failed-only-tests.md)

</details>

<details>

<summary>GitLab CI</summary>

See our step-by-step guide [Re-run Only Failed Tests](/getting-started/ci-setup/gitlab/re-run-failed-only-tests.md)

</details>

<details>

<summary>Jenkins Pipeline</summary>

See our step-by-step guide to [Setting up retries of failed job with Jenkins Pipeline](https://docs.currents.dev/getting-started/ci-setup/jenkins#using-last-failed-flag-with-shards-and-orchestration)

</details>


---

# 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/guides/ci-optimization/re-run-only-failed-tests.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.
