# Playwright Test Runner (`jindrich.bar/playwright-test`) Actor

Run Playwright tests across numerous browser configurations with Apify. Create your tests in seconds and get comprehensive test reports faster than ever.

- **URL**: https://apify.com/jindrich.bar/playwright-test.md
- **Developed by:** [Jindřich Bär](https://apify.com/jindrich.bar) (community)
- **Categories:** Automation, Developer tools, Open source
- **Features:** Full permissions
- **Stats:** 66 total users, 0 monthly users, 100.0% runs succeeded, 5 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Playwright Test

Run your Playwright tests on the Apify Platform effectively and easily. Just set up your test environment using a user-friendly UI and let the platform do the rest.

### Features

#### Run your Playwright tests on the Apify Platform

No more pre-commit hooks or CI/CD pipelines. Integrate your tests with the Apify Platform using a user-friendly UI and forget about the hassle of setting up your test environment.

<center>
<img src="https://raw.githubusercontent.com/apify/playwright-test-actor/main/docs/static/actorInput.gif" alt="Test configuration with comprehensive UI">
</center>

#### Collect and analyze your test results online

After running the tests, the Apify Platform stores the results in comprehensive datasets. You can view the results directly on the platform or download them to your local machine using a REST API.

<center>
<img src="https://raw.githubusercontent.com/apify/playwright-test-actor/main/docs/static/testReport.gif" alt="Analyzing understandable test reports">
</center>

#### No more problems with incompatible browser versions

Playwright Test toolkit automatically downloads the latest versions of Chromium, Firefox, and WebKit browsers and installs them in the Apify Platform.

This way, you can test your websites using all the popular browsers without worrying about compatibility issues.

<center>
<img src="https://raw.githubusercontent.com/apify/playwright-test-actor/main/docs/static/devices.gif" alt="Testing with multiple browser versions at once">
</center>

### How to use

To run tests with the Playwright Test Actor, just copy-paste your generated test code into the *Test Suite code* field in the Actor settings.

You can also customize the test run by specifying other options in the settings, e.g. the screen size, headful/headless execution or the maximum run time.

# Actor input Schema

## `testCode` (type: `string`):

Contents of the test suite file.

## `screenWidth` (type: `integer`):

Screen width in pixels. Default is `1280`.

## `screenHeight` (type: `integer`):

Screen height in pixels. Default is `720`.

## `headful` (type: `boolean`):

Runs tests in headful mode. Try turning this on if you are having problems e.g. with bot protection services. Default is `false`.

## `darkMode` (type: `boolean`):

Should the tests run in the dark mode? Default is `false`.

## `locale` (type: `string`):

Locale to use for the test. Default is `en-US`.

## `timeout` (type: `integer`):

Maximum run time for the entire test suite (in seconds). Default is `60`.

## `video` (type: `string`):

Record video of the test run. If set to 'retain-on-failure', video will be recorded only if the test fails. If set to 'on-first-retry', video will be recorded only on the first retry of the test.

## Actor input object example

```json
{
  "testCode": "import { test, expect } from '@playwright/test';    \n    test('has title', async ({ page }) => {      \n      await page.goto('https://playwright.dev/');\n      // Expect a title \"to contain\" a substring.\n      await expect(page).toHaveTitle(/Playwright/);    \n    });\n    test('get started link', async ({ page }) => {\n        await page.goto('https://playwright.dev/');\n        // Click the get started link.\n        await page.getByRole('link', { name: 'Get started' }).click();\n        // Expects the URL to contain intro. \n        await expect(page).toHaveURL(/.*intro/);    \n    });",
  "screenWidth": 1280,
  "screenHeight": 720,
  "headful": false,
  "darkMode": false,
  "locale": "en-US",
  "timeout": 60,
  "video": "off"
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "testCode": `import { test, expect } from '@playwright/test';    
    test('has title', async ({ page }) => {      
      await page.goto('https://playwright.dev/');
      // Expect a title "to contain" a substring.
      await expect(page).toHaveTitle(/Playwright/);    
    });
    test('get started link', async ({ page }) => {
        await page.goto('https://playwright.dev/');
        // Click the get started link.
        await page.getByRole('link', { name: 'Get started' }).click();
        // Expects the URL to contain intro. 
        await expect(page).toHaveURL(/.*intro/);    
    });`
};

// Run the Actor and wait for it to finish
const run = await client.actor("jindrich.bar/playwright-test").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "testCode": """import { test, expect } from '@playwright/test';    
    test('has title', async ({ page }) => {      
      await page.goto('https://playwright.dev/');
      // Expect a title \"to contain\" a substring.
      await expect(page).toHaveTitle(/Playwright/);    
    });
    test('get started link', async ({ page }) => {
        await page.goto('https://playwright.dev/');
        // Click the get started link.
        await page.getByRole('link', { name: 'Get started' }).click();
        // Expects the URL to contain intro. 
        await expect(page).toHaveURL(/.*intro/);    
    });""" }

# Run the Actor and wait for it to finish
run = client.actor("jindrich.bar/playwright-test").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "testCode": "import { test, expect } from '\''@playwright/test'\'';    \\n    test('\''has title'\'', async ({ page }) => {      \\n      await page.goto('\''https://playwright.dev/'\'');\\n      // Expect a title \\"to contain\\" a substring.\\n      await expect(page).toHaveTitle(/Playwright/);    \\n    });\\n    test('\''get started link'\'', async ({ page }) => {\\n        await page.goto('\''https://playwright.dev/'\'');\\n        // Click the get started link.\\n        await page.getByRole('\''link'\'', { name: '\''Get started'\'' }).click();\\n        // Expects the URL to contain intro. \\n        await expect(page).toHaveURL(/.*intro/);    \\n    });"
}' |
apify call jindrich.bar/playwright-test --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,jindrich.bar/playwright-test"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/ERtrn4late1N6aSiN/builds/gQ0hOsWq43SCt8jEc/openapi.json
