# Use prerequisites and dependencies

Some tests need another flow to happen first. TestVibe can model that relationship with prerequisites or dependent tests.

Use dependencies when one test creates or prepares the state another test needs.

## When To Use A Prerequisite

Use a prerequisite when:

| Situation                                  | Example                                                |
| ------------------------------------------ | ------------------------------------------------------ |
| A setup flow is reused                     | Sign in before account settings tests.                 |
| One feature creates required data          | Create a customer before editing customer details.     |
| A path is too long to repeat               | Complete onboarding before testing dashboard behavior. |
| A setup step should be reviewed separately | Create invoice before testing invoice download.        |

Do not use dependencies for every small step. If setup is short and only belongs to one scenario, keep it in the scenario or `Background`.

## Example

Prerequisite feature:

```gherkin
Feature: Customer creation

  Scenario: Admin creates an active customer
    Given the admin is on the customers page
    When the admin creates a customer named "Acme QA"
    Then the customer record should be visible
```

Dependent feature:

```gherkin
Feature: Customer billing

  Scenario: Admin updates billing contact
    Given the "Acme QA" customer exists
    When the admin updates the billing contact email
    Then the new billing contact should be saved
```

The dependent feature can refer to the setup expectation without repeating every creation step.

## How Dependencies Affect Maintenance

When you change a prerequisite, review the tests that depend on it.

| Change                   | What to check                                         |
| ------------------------ | ----------------------------------------------------- |
| Rename fields or buttons | Dependent generated tests may need regeneration.      |
| Change created data      | Dependent tests may need updated expected values.     |
| Move the setup flow      | Dependent features may need clearer starting context. |
| Delete the prerequisite  | Dependent tests may no longer be runnable.            |

## Keep Dependencies Understandable

Good dependency chains are short and intentional.

Do:

* use one setup feature for a clear purpose
* describe the state the dependent test expects
* keep prerequisite names specific
* regenerate dependent tests after meaningful setup changes

Avoid:

* long chains of dependencies
* hidden setup that is not mentioned in the dependent scenario
* relying on fragile data created by another team's manual process

## Alternatives

| Need                                           | Better option                                                           |
| ---------------------------------------------- | ----------------------------------------------------------------------- |
| Shared setup for every scenario in one feature | Use `Background`.                                                       |
| One-time repository or environment setup       | Use project settings, secrets, or test data setup outside the scenario. |
| A short setup action used once                 | Keep it inside the scenario.                                            |
| A repeated multi-step setup journey            | Use a prerequisite or dependent test.                                   |

## Next

After defining dependencies, generate or regenerate the affected tests. See [Generate Playwright code](/ai-generation/generate-playwright-code.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/create-tests/use-prerequisites-and-dependencies.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.
