# Playwright (JS/TS)

## Installation

First we need to install cloudbeat/playwright in your project:

```
npm install @cloudbeat/playwright
```

Then add cloudbeat as the reporter inside playwright.config:

```
reporter: process.env.CB_AGENT ? '@cloudbeat/playwright' : 'html'
```

In order to save screenshots and videos in cloudbeat, make sure to enable them:

```typescript
  use: {
    trace: "on-first-retry",
    video: "on-first-retry",
    screenshot: "only-on-failure",
    headless: process.env.CB_AGENT ? true : false
  },
```

{% hint style="info" %}
When setting `video`, `screenshot`, or `trace` to `on`, Playwright will generate attachments for **every action**, even if it succeeds. This is generally **not recommended**, as it creates many unnecessary files and increases storage and execution time.\
Instead, it's better to use the `on-first-retry` option, which only captures these artifacts if a test fails for the first time (on the first retry). This approach provides a good balance between debugging needs and resource efficiency.
{% endhint %}

{% hint style="info" %}
Since CloudBeat agents run on Linux-based environment, enabling headless mode is mandatory and resulting in faster test execution and more efficient CPU and memory utilization.
{% endhint %}

## Creating a Playwright project in Cloudbeat

Under Manage, open projects and click on add project, choose a name and select Playwright

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2F4opAK0fKCTUssmpDjfpE%2Fimage.png?alt=media&#x26;token=147f4e63-7510-4408-adb1-cec5ef25d3bf" alt=""><figcaption></figcaption></figure>

### Connect your test project to CloudBeat

CloudBeat is a platform for both test reporting and execution. To use CloudBeat, you must upload your test project files to execute tests and access report analytics. You can upload your project as a Zip file, or CloudBeat can automatically synchronize with your test project Git repository.

### Git synchronization

In order to sync your test project from git, select Git Integration and paste the url to your repository.

You can use your username and password, or with an access token.

### Uploading manually&#x20;

If you want to upload a local test project, you need to zip your project folder, then select upload.

{% hint style="warning" %}
**Make sure you skip node\_modules, and preferably all the unnecessary files such as results, reports, etc.**
{% endhint %}

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2Fwmm91RqvC7433FTOaOJO%2Fimage.png?alt=media&#x26;token=69846d62-66b4-4814-8902-e65468faab70" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2FnmIHStfyYyblIuCNtRrS%2Fimage.png?alt=media&#x26;token=42e95d5c-0a64-4256-a234-c76b221abd0e" alt=""><figcaption></figcaption></figure>

## Configuring Environments

Under manage, open Environments and recreate the values that you have inside your .env file.

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2FrbvNNcUVbtN24dN0kxjn%2Fimage.png?alt=media&#x26;token=f56be553-98b4-4758-a4b8-633e1a731f0b" alt=""><figcaption></figcaption></figure>

## Running your tests

Under Testing, go to cases and you will see all your tests, make sure Location is enabled under test mode, click on Run Now to execute the selected test on your selected location.

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2FDnHfYuPeeEckyv5yJ2A6%2Fimage.png?alt=media&#x26;token=48b32d6c-a52f-4381-9ae9-a680f3d6bc2a" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2Fu1CFD8d6MN5N67vpfPmz%2Fimage.png?alt=media&#x26;token=202b67c5-6e72-4d8e-b2e5-a8aaabbb3b80" alt=""><figcaption></figcaption></figure>

After your test is completed, click on the results tab to see all of the test steps, videos, logs and data.

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2F70suExuk8KIQG9Uf2EBV%2Fimage.png?alt=media&#x26;token=bb97ef6e-b2ef-4e9e-9d73-f7a18a405762" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2Fdvq2qTS47DYDHxnEcN4j%2Fimage.png?alt=media&#x26;token=d8357b9e-b4af-4013-8450-62e4c850bba3" alt=""><figcaption></figcaption></figure>

### Running multiple tests

Under Testing, go to Suites, right-click on Dashboard to create a new suite, or start by creating a new folder then right-click on it and choose Create suites - web.

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2FTwjZ00cKeJCzA70eyB2H%2Fimage.png?alt=media&#x26;token=e6a9cf2d-d8c0-49bf-91d5-40619dd299e8" alt=""><figcaption></figcaption></figure>

Go to settings and make sure test mode is set to Location, save changes and choose your location.

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2Fzi4NguuWrKfVqdnz2HQT%2Fimage.png?alt=media&#x26;token=6033228c-47cf-41b8-b315-6e9f5071365e" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2FgDGgTVXp1ka123V2vymu%2Fimage.png?alt=media&#x26;token=d3d43120-9e90-49f9-9f15-f49d1717d785" alt=""><figcaption></figcaption></figure>

Click on the cases tab and select your desired cases.

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2F73sIgZ7R17hlvaksvkAB%2Fimage.png?alt=media&#x26;token=60ba6925-1d1a-4433-8e87-68be83838330" alt=""><figcaption></figcaption></figure>

Similar to a single case, clicking on Run Now will execute all the selected cases.

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2FItnlaKEo6Ua1YOozfXha%2Fimage.png?alt=media&#x26;token=e3ceea7f-6648-480e-8025-d06b05e7e428" alt=""><figcaption></figcaption></figure>

Under results tab, you will see the status of your tests.

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2FYqOpVrpJRpnD9DmmMCJD%2Fimage.png?alt=media&#x26;token=43ae5e4a-1305-4332-a48e-980b6b802774" alt=""><figcaption></figcaption></figure>
