> ## Documentation Index
> Fetch the complete documentation index at: https://docs.testdriver.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Test Generation with TestDriver

> Simplify test creation with AI-driven exploratory testing.

Writing tests can be a tedious and time-consuming task. TestDriver can generate tests just by exploring your app. This guide will show you how to generate tests using TestDriver.

# Generate exploratory tests

Launch `testdriverai` in interactive mode with the following command:

```bash theme={null}
npx testdriverai@latest
```

TestDriver will boot up.

```bash theme={null}
❯ testdriverai
Howdy! I'm TestDriver v6.0.0
```

Ensure your website or app is visible on your test runner's display.

Then, run the `generate` command.

```bash theme={null}
/generate web 10
```

This will generate 10 tests within the `testdriver/generate` directory. You can change the number of tests generated by changing the number after `10`. The generated tests will be in the form of a `.yaml` file, and you can run them using your test runner of choice (local or cloud hosted).

```bash theme={null}
> /generate web 5

thinking...
```

Now your directory structure will look like this:

```bash theme={null}
testdriver
├── generate
│   ├── test-error-user-login.yaml
│   ├── test-locked-out-user-login.yaml
│   ├── test-navigation-to-shop-page.yaml
│   ├── test-problem-user-login.yaml
│   └── test-standard-user-login.yaml
```

Notice that each test file has no commands! It's only a list of prompts. This is similar to an exploratory test.

```yaml theme={null}
version: 5.3.11
steps:
  - prompt: Fill in the "Username" field with "error_user".
  - prompt: Fill in the "Password" field with "secret_password".
  - prompt: Click the "Sign in" button.
  - prompt: Assert that there are issues during checkout and an error is displayed.
```

# Generate regression tests from exploratory tests

Now it's time to generate the regression test.

Run the tests with the [`run`](/commands/run) command and use the `--write` parameter:

```bash theme={null}
npx testdriverai@latest run testdriver/generate/test-error-user-login.yaml --write
```

When a test has no `commands`, TestDriver falls back to the `prompt`.

```
> Fill in the "Username" field with "error_user".
No commands found, running exploratory
```

When using the `--write` command, TestDriver appends any generated commands to the test file.

So as your test run, TestDriver will append successful commands to the YAML file and save it.

<YmlWarning />

```yaml theme={null}
version: 5.3.11
steps:
  - prompt: Focus the browser window.
    commands:
      - command: focus-application
        name: Google Chrome
      - command: hover-text
        text: Username
        description: username input label in the login form
        action: click
  - prompt: Fill in the "Password" field with "secret_password".
    commands:
      - command: hover-text
        text: Password
        description: password input label in the login form
        action: click
      - command: type
        text: secret_password
      - command: hover-text
        text: Password
        description: password input field in the login form
        action: click
```

Now the next time you run the test, TestDriver will use the commands instead of the prompt!

```bash theme={null}
npx testdriverai@latest run testdriver/generate/test-error-user-login.yaml
```
