Manage Targets

Playwright Specs

Modern web applications are built around complex, state-driven business workflows that cannot be accurately tested through simple crawling alone. Critical flows such as multi-step checkout processes, HR onboarding journeys, approval chains, support ticket escalations, and role-based feature access require precise sequencing, authenticated states, and conditional logic.

Traditional automated crawlers lack business context and frequently fail to traverse these workflows correctly. As a result, important parts of the application may remain untested.

To address this gap, ZeroThreat supports Playwright Specs integration. You can use your existing Playwright test suites to execute real business workflows during security scans, providing deeper coverage across conditionally accessible features and complex user flows that automated crawling alone cannot reliably reach.

ZeroThreat supports Playwright projects written in:

  • TypeScript / JavaScript
  • Python
Feature Availability
Playwright Specs integration is available exclusively in Enterprise Cloud and Enterprise On-Prem plans. Check out ZeroThreat Plans page for more.

Setting Up Playwright Specs in ZeroThreat

Step 1: Navigate to Targets

Go to the Targets section from ZeroThreat dashboard

Select Target Image

Step 2: Select the Target

Click on the Select Target Image specific target you wish to configure. This will open the Target Configuration settings.

Step 3: Open Playwright Specs

Inside Target Configuration, click on the Playwright Specs section.

Thumbnail

You will see two options to upload or connect your Playwright project. However, Before importing your project, make sure it is prepared to run inside ZeroThreat using the configuration requirements for your project type described below.

Two Quick Ways to Create Playwright Specs (Optional)

If you already have a Playwright project, you can skip this section and continue to Preparing Your Playwright Project for ZeroThreat.

The methods below provide quick ways to create Playwright Specs using the standard JavaScript / TypeScript Playwright tooling.

Method 1: Using Playwright Codegen

This is one of the fastest ways to create Playwright Specs by recording browser interactions.

  1. Create and open an empty project folder:
mkdir playwright-specs
cd playwright-specs
  1. Initialize a Node.js project:
npm init -y
  1. Set up Playwright:
npm init playwright@latest
  1. Once Playwright is installed, start Codegen against your target application:
npx playwright codegen https://your-target-url.com

This opens a browser and begins recording your actions. As you interact with the application, Playwright generates the corresponding test steps.

  1. Create a spec file inside your tests folder and save the generated steps into it, for example:
mkdir -p tests
  1. Save the recorded flow into a file such as:
tests/login-flow.spec.ts
  1. Run the spec to confirm it works:
npx playwright test

For more information, Refer https://playwright.dev/docs/codegen#generate-tests-with-the-playwright-inspector

Method 2: Using Playwright Test Agents - Planner, Generator, and Healer

This method is useful when you want agent-assisted help to create Playwright Specs from scratch. Playwright provides three built-in test agents: planner, generator, and healer. The usual flow is to let the planner explore the app and produce a Markdown test plan, then let the generator turn that plan into Playwright Test files, and finally use the healer to repair failing tests.

1. Create and open an empty project folder.

mkdir playwright-specs
cd playwright-specs

2. Initialize a Node.js project.

npm init -y

3. Create a Playwright project.

npm init playwright@latest

This creates the base Playwright project structure so you can start generating tests.

4. Generate the Playwright agent definitions for VS Code.

npx playwright init-agents --loop=vscode

Playwright recommends regenerating these agent definitions whenever Playwright is updated so the agents pick up new tools and instructions. VS Code version 1.105 or later is required for this agentic experience.

AI Assistant Setup for Playwright Test Agents
Playwright Test Agents work through an AI assistant in VS Code. Before using the Planner, Generator, or Healer, make sure your VS Code AI setup is ready and has access to a supported model.

If you are using GitHub Copilot, ensure Copilot is installed, signed in, and able to use an available model. VS Code also supports choosing between available language models and, in some setups, bringing your own language model API key. Refer to the VS Code AI language model setup documentation for more details: AI language models in VS Code.

Run the following command to generate the Playwright agent definitions for the VS Code workflow:

npx playwright init-agents --loop=vscode
This generates the Playwright Planner, Generator, and Healer agent definitions. Playwright recommends regenerating these definitions whenever Playwright is updated so the agents can use the latest tools and instructions.

If you are using a different AI coding assistant, such as Codex, the generated Playwright agents may not appear as native selectable agents inside that assistant’s panel. In that case, manually ask the assistant to read and follow the generated Playwright agent instructions when planning, generating, or healing tests.

5. Create a seed test.

The planner expects a seed test that sets up the environment needed to interact with your app. Playwright states that the planner uses this test to run initialization such as global setup, project dependencies, fixtures, and hooks, and also uses it as an example for generated tests.

Create a simple seed test such as:

import { test } from '@playwright/test';

test('seed', async ({ page }) => {
  await page.goto('https://your-app-url.com');
});

Save it as:

tests/seed.spec.ts

6. Ask the planner to create a bounded and precise plan.

The planner explores your app and produces a Markdown test plan for one or more scenarios and user flows. It works best when the request is narrow and explicit. Avoid vague requests like “cover the whole app.” Instead, tell it exactly what flow should be automated, where it starts, what success looks like, and which seed test it should use.

A very basic prompt can be:

Generate a plan for a Playwright spec that logs into the application, opens the billing page, verifies that the invoices table is visible, and logs out. Use tests/seed.spec.ts as the seed test. Keep the plan focused only on this flow.

Bounded, precise planner tasks usually give better results than broad ones.

7. Review the generated Markdown plan.

The planner produces a human-readable Markdown plan under specs/, such as specs/basic-operations.md. Review it before continuing and make sure it matches the exact workflow you want.

8. Pass the approved plan to the generator.

The generator takes the Markdown plan from specs/ and converts it into executable Playwright Test files under tests/. Playwright notes that the generator verifies selectors and assertions live while performing the scenarios.

Your end result should be a clean spec file such as:

tests/billing-flow.spec.ts

9. Run the generated tests.

npx playwright test

Or run only the generated spec:

npx playwright test tests/billing-flow.spec.ts

10. Use the healer if the spec fails.

When a test fails, the healer replays the failing steps, inspects the current UI, suggests a patch such as a locator update or wait adjustment, and reruns the test until it passes or until its guardrails stop the loop.

11. Review the healed result and make manual corrections where needed.

The healer can fix many practical issues, but it should not replace human review. After healing, check whether the final test is still doing exactly what you intended. If selectors, waits, assertions, or flow logic still need adjustment, update the spec manually and run it again.

12. Repeat the same flow for additional user journeys.

This workflow works best when the requested plan is bounded and precise. Smaller, clearly defined flows are easier for the planner to map, easier for the generator to turn into useful specs, and easier for the healer to fix when something breaks. This also aligns with Playwright’s documented flow of planner to generator to healer producing test coverage sequentially.

For more information, Refer https://playwright.dev/docs/test-agents

Once the spec runs successfully, it is ready to be adapted for ZeroThreat by applying the proxy configuration described below.

Preparing Your Playwright Project for ZeroThreat

ZeroThreat can execute both JavaScript / TypeScript and Python Playwright projects.

The required setup differs slightly between the two runtimes.

  • JavaScript / TypeScript projects require a ZeroThreat proxy configuration inside the Playwright project.
  • Python projects do not require manual proxy configuration. ZeroThreat applies the scanning proxy automatically during execution.

JavaScript / TypeScript Projects

JavaScript / TypeScript projects require a small Playwright configuration change so browser traffic is routed through the ZeroThreat scanning proxy.

Configure JavaScript / TypeScript Playwright Specs

Before importing a JavaScript or TypeScript Playwright project, configure it so browser traffic is routed through the ZeroThreat scanning engine.

At the top of your playwright.config.ts, make sure devices is imported:

import { defineConfig, devices } from '@playwright/test'

In your default Playwright configuration, keep the project running in headless mode. If you already have headless: true set, keep it as it is. Otherwise, do not explicitly add or override this setting.

You should also structure your Playwright project so that each individual spec completes within 30 seconds. This is the timeout used for Playwright Spec execution inside ZeroThreat. You can have as many individual specs as needed, but each spec should stay within that limit to ensure the best coverage.

Inside your playwright.config.ts, add the following project configuration under projects:

{
    name: 'ZT-Proxy-Chromium',
    use: {
        ...devices['Desktop Chrome'],
        proxy: {
            server: 'http://localhost:8000',
        },
        ignoreHTTPSErrors: true,
    },
}

This ensures that Playwright traffic flows through the ZeroThreat scanning engine.

Inside your package.json, add the following script under scripts:

"zt:test": "npx playwright test --project=ZT-Proxy-Chromium"
Keep your Playwright Specs focused and modular. Smaller specs are easier to maintain, easier to debug, and more reliable during scans.

After these changes, your existing Playwright Specs will automatically execute within ZeroThreat without requiring any modifications to your test spec logic.

Python Projects

Python projects are automatically detected from their dependency files and do not require manual proxy configuration. Expand this section to review project detection, dependency requirements, test execution options, and spec-level reporting.

Configure Python Playwright Specs

ZeroThreat also supports Playwright Specs written in Python, including projects using pytest, pytest-playwright, direct Playwright APIs, or custom test runners.

Python Project Detection

Python projects are automatically detected when the selected repository path or uploaded project contains one of the following files:

  • requirements.txt
  • pyproject.toml
  • uv.lock

If a package.json is present at the same project level, the project is not automatically treated as a Python project.

Using a monorepo?
When connecting a repository containing multiple projects, select the path that represents the Playwright project you want ZeroThreat to execute.
Project detection is performed using the files available within the selected project path.
No manual proxy setup required
Unlike JavaScript / TypeScript projects, Python Playwright projects do not need proxy configuration added to the test code.
ZeroThreat automatically routes Playwright traffic through the scanning proxy during execution for both sync_api and async_api based tests.

Dependency Files

Your Python project must contain at least one supported dependency file at the project root or configured repository path:

  • requirements.txt
  • pyproject.toml
  • uv.lock

ZeroThreat installs the project dependencies automatically before executing the tests, including the required Playwright browsers.

Choosing How Your Tests Run

ZeroThreat needs to determine which command should execute your test suite.

There are two supported approaches.

Option 1: Standard pytest projects

If your project uses a standard pytest setup, including pytest-playwright fixtures or direct use of sync_playwright(), ZeroThreat automatically detects the project style and executes the tests.

No additional ZeroThreat configuration is required.

Option 2: Custom test command

If your project does not use a standard pytest setup, you can explicitly define the command ZeroThreat should execute.

This can be useful for projects using:

  • behave
  • Robot Framework
  • tox
  • nox
  • custom CLI wrappers
  • custom test entrypoints
  • non-standard pytest commands

Add a [tool.zerothreat] section to your pyproject.toml:

[tool.zerothreat]
test_command = "python -m pytest -m 'not flaky' --tb=short"

ZeroThreat runs the command exactly as configured inside the project's Python environment, with the scanning proxy already active.

If no test_command is declared and the project is not recognized as a standard pytest setup, ZeroThreat attempts a default pytest run.

Getting Spec-Level Reporting

For the best visibility in the Scan Report, your test run should generate a pytest-json-report compatible report.json.

This allows ZeroThreat to associate execution results and network activity with individual specs instead of only recording the overall test run result.

For standard pytest projects, this is handled automatically.

If you use a custom test_command, include:

--json-report --json-report-file=report.json

For example:

[tool.zerothreat]
test_command = "python -m pytest -m 'not flaky' --tb=short --json-report --json-report-file=report.json"

Without this report, ZeroThreat can still determine whether the overall test command passed or failed, but individual spec-level results cannot be displayed.

Python Test Execution Requirements

Python Playwright projects should run their tests serially.

Avoid parallel execution plugins or options such as:

pytest -n auto

Parallel execution may cause network activity generated by one test to be incorrectly attributed to another spec in the Scan Report.

Keep each test focused on a specific workflow and avoid combining several large business flows into a single test.

Test Execution Requirements

Regardless of the project language, structure your Playwright Specs so that each individual test completes within 30 seconds.

You can include as many individual specs as required, but every spec should remain within this execution limit.

For the most reliable scan coverage:

  • Keep individual specs focused on a single workflow or logical flow.
  • Avoid unnecessary waits or long-running operations.
  • Make sure the test runs successfully before importing it into ZeroThreat.
  • Keep tests modular so failures in one workflow do not prevent unrelated workflows from executing.

Upload Methods

Once your Playwright project is prepared, you can add it to ZeroThreat using either GitHub or a ZIP upload.

The same import methods are used for JavaScript / TypeScript and Python projects.

Method 1: Import from GitHub

Use this method to connect your existing Playwright GitHub repository directly to ZeroThreat using the ZeroThreat GitHub App.

Follow these steps:

  1. Click the Connect Your GitHub Repository card. In the popup, click Connect GitHub.
Thumbnail
Make sure you are logged in to GitHub in the same browser profile. If not, you can log in during the next step.
  1. You will be redirected to the GitHub App access page.
Thumbnail
  1. Select the repository that contains your Playwright Specs and grant access to the ZeroThreat AI GitHub App. Click Save to complete the GitHub App authorization.
Thumbnail
  1. After the connection is successful, you will see a GitHub App Installed confirmation page.
Thumbnail
  1. Back in ZeroThreat Portal, select:
  • your repository
  • the path to your Playwright Specs in the repository
  • optionally, the branch name
Thumbnail

The selected path should point to the root of the project ZeroThreat should execute.

For JavaScript / TypeScript projects, this should contain the relevant Playwright project files such as:

package.json
playwright.config.ts

For Python projects, the selected path should contain one of:

requirements.txt
pyproject.toml
uv.lock

If the Python project uses a custom ZeroThreat test command, make sure the corresponding pyproject.toml containing [tool.zerothreat] is available at that path.

  1. Click Save.
Thumbnail

Once connected, your Playwright Specs will be used to improve coverage in future scans.

Method 2: Upload a ZIP File

You can also upload your Playwright project directly.

  1. Create a .zip file of the project containing playwright specs
  2. Make sure the required project configuration files are present at the ZIP root.

For a JavaScript / TypeScript project, include the required Node and Playwright configuration files, including:

package.json
playwright.config.ts

For a Python project, include at least one supported dependency file:

requirements.txt
pyproject.toml
uv.lock

If the Python project uses a custom ZeroThreat test command, also ensure that the pyproject.toml containing the [tool.zerothreat] configuration is included.

  1. Upload the ZIP file
Thumbnail
If your ZIP file is larger than 2 GB, use the Import from GitHub option instead.

Once uploaded, your Playwright Specs will be listed in the Playwright Specs section for that target.

Viewing Playwright Specs During a Scan

Once Playwright Specs are configured for a target, they will automatically run when you initiate a scan.

In Scan Report

After the scan completes:

  • Open the Scan Report
  • In the top-right dashboard, you will see a Playwright section
Thumbnail
  • Clicking it will display:
    • All specs executed during the scan
    • Execution status (Pass / Fail)
    • Execution time per spec
Thumbnail

During an Active Scan

While a scan is running, you can monitor Playwright spec execution progress within the AI-Driven Penetration view.

A dedicated Playwright Spec block will display:

  • Currently running specs
  • Execution status
  • Runtime information
Thumbnail

This allows you to verify that critical workflows using Playwright specs are being tested as expected.

Why Use Playwright Specs?

Integrating Playwright Specs provides:

  • Coverage for multi-step and stateful workflows
  • Testing of conditionally accessible features
  • Improved attack surface exploration beyond ZeroThreat static crawling

By combining automated crawling with application-specific Playwright workflows, ZeroThreat can explore more of the application's real functionality during a security scan.

Summary

Playwright Specs allow you to bring real application workflows into ZeroThreat security scans using your existing automation suites.

ZeroThreat supports Playwright projects written in JavaScript / TypeScript and Python. JavaScript / TypeScript projects require explicit ZeroThreat proxy configuration, while Python projects are automatically routed through the scanning proxy without requiring changes to individual tests.

Projects can be connected through GitHub or uploaded as a ZIP file. Once configured, the specs run automatically during scans, with execution status available during active scans and in the Scan Report.

For the best results, keep specs small, reliable, and focused on meaningful business workflows.