---
title: Playwright Recorder - Record tests | TestingBot
description: Record tests with Playwright Recorder and run these on a remote browser
  grid.
source_url:
  html: https://testingbot.com/support/web-automate/playwright/recorder
  md: https://testingbot.com/support/web-automate/playwright/recorder.md
---

# Playwright Recorder

Playwright offers a feature where you can record the actions in your browser to a Playwright script file.

This allows you to easily create tests by recording your own actions, similar to [Selenium IDE](https://testingbot.com/support/web-automate/codeless-automation/add-test).

To get started, install these packages:

```bash
npm install playwright
```

## Example

Now you can record your actions to a Playwright file:

```bash
npx playwright codegen --target javascript -o example.js https://testingbot.com
```

This command will start a Chromium browser and will record every action you take, in JavaScript format, to a file called `example.js`.

You can choose to save the file in a different format, these are the options:

- javascript
- python
- python-async
- csharp

The `example.js` file can contain something similar to this:

```javascript
const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch({
    headless: false
  });
  const context = await browser.newContext();

  // Open new page
  const page = await context.newPage();

  // Go to https://testingbot.com/
  await page.goto('https://testingbot.com/');

  // Click text=Take your automated and manual testing to the next level.
  await page.click('text=Take your automated and manual testing to the next level.');

  // Click img[alt="Automated Testing"]
  await page.click('img[alt="Automated Testing"]');

  // Close page
  await page.close();

  // ---------------------
  await context.close();
  await browser.close();
})();
```

## Run on TestingBot

To run the generated file on a browser in the TestingBot grid, you'll have to modify the script.

### Before

```javascript
const browser = await chromium.launch();
```

### After

```javascript
const capabilities = {
  'tb:options': {
    key: process.env.TB_KEY,
    secret: process.env.TB_SECRET
  },
  browserName: 'chrome',
  browserVersion: 'latest'
}
const browser = await chromium.connect({
  wsEndpoint: `wss://cloud.testingbot.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`
})
```

## Playwright Agents

An alternative approach to recording tests would be to generate tests from your existing code. Playwright comes with [3 agents](https://playwright.dev/docs/test-agents) that can be used to create tests.

- **planner** explores the app and produces a Markdown test plan
- **generator** transforms the Markdown plan into the Playwright Test files
- **healer** executes the test suite and automatically repairs failing tests, for example due to bad/missing locators

To get started, use this command to initialize the agent definitions:

```bash
npx playwright init-agents --loop=claude
```

You can now use your AI tool of choice to generate tests and point these to use a remote TestingBot browser by replacing the `launch` command with a `connect` command, as shown in the previous sections.

For example with a prompt: "Create one or more Playwright tests from the markdown test plan that was generated."

### Looking for more help?

Have questions or need more information? Reach out via email or Slack.

[Email us](https://testingbot.com/contact/new) [Join our Slack](https://join.slack.com/t/testingb0t/shared_invite/zt-3bcw9xch-jk19~6XPs_xBrsAgAedkCw)
