> ## 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.

# Vercel

> Integrate TestDriver with Vercel deployments using GitHub Actions.

This guide explains how to integrate **TestDriver** with **Vercel deployments** using the **GitHub Actions workflow**. By combining these tools, you can automatically test your Vercel preview deployments or production builds to ensure they meet your quality standards before merging or releasing.

***

## Workflow overview

1. **Trigger Vercel Deployment**: Use Vercel's GitHub integration to deploy your application on every pull request or push to the main branch.
2. **Run Tests on the Deployment URL**: Use the TestDriver GitHub Action to test the deployed application using the Vercel deployment URL.
3. **Report Results**: View test results in the GitHub Actions dashboard or as comments on the pull request.

***

## Prerequisites

1. **Vercel GitHub Integration**: Ensure your repository is connected to Vercel for automatic deployments.
2. **TestDriver API Key**: Store your API key as a GitHub secret (for example, `TD_API_KEY`).
3. **Vercel Deployment URL**: Use the `VERCEL_URL` environment variable provided by Vercel to access the deployment.

***

## CI/CD workflow

Here's a complete workflow to test Vercel deployments with TestDriver CLI (adapt for your CI/CD platform):

```yaml .github/workflows/testdriver-vercel.yaml theme={null}
name: Test Vercel Deployment with TestDriver

on:
  pull_request:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  test-vercel:
    name: Test Vercel Deployment
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v4

      - name: Wait for Vercel Deployment
        id: vercel
        uses: amondnet/vercel-action@v20
        with:
          vercel-token: ${{ secrets.VERCEL_TOKEN }}
          github-token: ${{ secrets.GITHUB_TOKEN }}
          vercel-args: "--prod" # Optional: Use '--prod' for production builds
        env:
          VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
          VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

      - name: Run Tests with TestDriver CLI
        run: npx testdriverai@latest run testdriver/test.yaml
        env:
          TD_API_KEY: ${{ secrets.TD_API_KEY }}
          DEPLOYMENT_URL: ${{ steps.vercel.outputs.url }}
```

***

## Workflow steps explained

### 1. **Wait for Vercel deployment**

The `amondnet/vercel-action` waits for the Vercel deployment to complete and retrieves the deployment URL. This URL is stored in the `steps.vercel.outputs.url` variable.

```yaml .github/workflows/testdriver-vercel.yaml theme={null}
- name: Wait for Vercel Deployment
  id: vercel
  uses: amondnet/vercel-action@v20
  with:
    vercel-token: ${{ secrets.VERCEL_TOKEN }}
    github-token: ${{ secrets.GITHUB_TOKEN }}
    vercel-args: "--prod"
  env:
    VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
    VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
```

***

### 2. **Run tests with TestDriver CLI**

The TestDriver CLI runs tests on the deployed application using the deployment URL.

```yaml .github/workflows/testdriver-vercel.yaml theme={null}
- name: Run Tests with TestDriver CLI
  run: npx testdriverai@latest run testdriver/test.yaml
  env:
    TD_API_KEY: ${{ secrets.TD_API_KEY }}
    DEPLOYMENT_URL: ${{ steps.vercel.outputs.url }}
```

***

## Secrets configuration

Add the following secrets to your GitHub repository:

1. **`TD_API_KEY`**: Your TestDriver API key.
2. **`VERCEL_TOKEN`**: Your Vercel API token.
3. **`VERCEL_ORG_ID`**: Your Vercel organization ID.
4. **`VERCEL_PROJECT_ID`**: Your Vercel project ID.

***

## Benefits of this workflow

1. **Automated Deployment Testing**: Automatically test every Vercel deployment, including preview and production builds.
2. **Early Issue Detection**: Catch issues in pull requests before merging.
3. **Detailed Feedback**: View test results directly in the GitHub Actions dashboard.
4. **Seamless Integration**: Combine Vercel's deployment capabilities with TestDriver's testing power.

***

By integrating TestDriver with Vercel deployments, you can ensure that every deployment is thoroughly tested, reducing the risk of bugs reaching production and improving the overall quality of your application.
