> For the complete documentation index, see [llms.txt](https://docs.testvibe.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.testvibe.com/ai-generation/generate-playwright-code.md).

# Generate Playwright Code

Generate Playwright code when your feature intent is ready and you want a runnable browser test.

The generated code is stored in your project and can be run from TestVibe.

{% hint style="info" %}
TestVibe generates standard [Playwright](https://playwright.dev/) tests. See the official [Playwright documentation](https://playwright.dev/docs/intro) for the full API and testing concepts.
{% endhint %}

## Before You Generate

Confirm:

| Check                            | Why it matters                                                                            |
| -------------------------------- | ----------------------------------------------------------------------------------------- |
| The feature is saved             | Generation uses the saved project version of the feature.                                 |
| The Gherkin is clear             | Better intent produces better code.                                                       |
| The target site URL is reachable | The cloud test session and generated test need to open the app.                           |
| Required secrets exist           | Login credentials the test needs must be available in **Settings > Variables & Secrets**. |

## Steps

1. Open the **Test Suite**.
2. Select the feature you want to generate.
3. Start the generation action from the feature details or test list.
4. Confirm the site URL and options.
5. Keep the default reasoning effort unless your team has a reason to change it.
6. Start generation.
7. Stay on the generation progress view until it finishes.
8. Open the generated output after success.

## What TestVibe Generates

Generation can create or update:

| Output                     | Purpose                                                        |
| -------------------------- | -------------------------------------------------------------- |
| Playwright test file       | The browser automation that runs the scenario.                 |
| Supporting output          | Helpers, configuration use, or generated metadata when needed. |
| Evidence during generation | Screenshots, section progress, and trace links when available. |
| Project changes            | Generated files saved to your project.                         |

## Review Before Running

Before running the generated test, check:

* it follows the intended journey
* it uses the right target page
* it verifies the expected result
* it does not depend on private or accidental data
* it does not ignore important setup from the Gherkin

For more detail, see [Read generated output](/ai-generation/read-generated-output.md).

## If The Output Is Not Right

Do not keep regenerating blindly. First improve the feature:

| Problem                     | Better next step                                                                           |
| --------------------------- | ------------------------------------------------------------------------------------------ |
| Test clicks the wrong thing | Add visible labels or clearer page context to the Gherkin.                                 |
| Test misses the assertion   | Add a stronger `Then` step.                                                                |
| Test needs setup            | Add `Background`, a prerequisite, or test data instructions.                               |
| Site could not be reached   | Fix the URL, or use a tunnel device for private apps.                                      |
| A secret token is missing   | Add the value in **Settings > Variables & Secrets** and match the `{{secret:NAME}}` token. |

Then regenerate. See [Regenerate a test](/ai-generation/regenerate-test.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.testvibe.com/ai-generation/generate-playwright-code.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
