# Regenerate a test

Regenerate when the generated output does not match the behavior you intended, or when the feature changed.

Regeneration is most effective after you improve the inputs. Re-running generation without changing anything often produces the same kind of problem.

## Good Reasons To Regenerate

| Reason                       | Example                                                           |
| ---------------------------- | ----------------------------------------------------------------- |
| You edited Gherkin           | Added clearer steps or a stronger assertion.                      |
| The app changed              | Labels, pages, or behavior changed since the last generation.     |
| The output missed the intent | The generated code clicked the wrong thing or skipped a result.   |
| Setup was fixed              | API key, secret, site URL, runner, or test data is now available. |
| Generation failed            | You addressed the failure and want another attempt.               |

## Before Regenerating

Review the previous output and decide what input needs to change.

| Problem                           | Improve this first                                               |
| --------------------------------- | ---------------------------------------------------------------- |
| Wrong page or flow                | Starting context and target site URL.                            |
| Weak assertion                    | `Then` steps and expected visible outcomes.                      |
| Missing login or setup            | `Background`, prerequisite tests, or secrets.                    |
| Wrong UI element                  | Visible labels, button names, field names, or role descriptions. |
| Workflow failed before generation | API keys, repository permissions, or runner configuration.       |

## Steps

1. Open the feature in the Test Suite.
2. Review the previous generation details if available.
3. Edit the Gherkin or repository settings that caused the issue.
4. Save the feature.
5. Start generation again.
6. Watch progress.
7. Review the generated output before running.

If your screen offers **Save and generate**, use it after making the Gherkin changes.

## What Might Be Replaced

Regeneration can update generated Playwright files. If your team manually edited generated code, those edits may be overwritten or need to be reapplied.

Before regenerating, consider:

* whether manual code changes should be moved into clearer Gherkin
* whether the code change belongs in a reusable helper
* whether the generated file should be reviewed in GitHub after regeneration

## After Regeneration

Run one test first. If it passes, you can run the group or suite.

If it fails, inspect the result evidence. A failed run can mean:

* the app has a real bug
* test data is missing
* the generated code still needs improvement
* the site or runner setup is wrong

For result review, see [Inspect failed steps](/results/inspect-failed-steps.md).


---

# Agent Instructions: 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:

```
GET https://docs.testvibe.com/ai-generation/regenerate-test.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
