# How to Add Context to Testpilot Tests
Source: https://www.jetify.com/docs/docs/testpilot/guides/add-context-to-tests

Improve test accuracy by adding context to your Testpilot tests. Learn when and how to provide application details and requirements.

## What is Context?[​](#what-is-context "Direct link to What is Context?")

Context in Testpilot is additional information that helps the AI better understand:

* How your application works
* Special requirements or conditions for tests
* Expected behaviors or edge cases
* Login credentials or test data

Context is passed to the AI model along with your test steps, helping it make better decisions
during test execution.

## Adding Context to Your Tests[​](#adding-context-to-your-tests "Direct link to Adding Context to Your Tests")

You can add context at two levels in your pilot files:

### 1. Global Context (Test Suite Level)[​](#1-global-context-test-suite-level "Direct link to 1. Global Context (Test Suite Level)")

Global context applies to all test cases in a file. Add it at the root level of your test file:

```yaml theme={null}
name: "E-commerce Test Suite"
login_url: "https://example.com/login"
context:
  - text: "This is an e-commerce site that sells electronics"
  - text: "The navigation menu is at the top of every page"
  - text: "Product search requires at least 3 characters"
  - text: "Prices are displayed in USD"
cases:
  # Test cases will inherit all the context above
  - id: "test-001"
    # ...
```

### 2. Test-Specific Context (Test Case Level)[​](#2-test-specific-context-test-case-level "Direct link to 2. Test-Specific Context (Test Case Level)")

Test-specific context applies only to a single test case:

```yaml theme={null}
cases:
  - id: "checkout-test-001"
    name: "Complete Checkout"
    description: "Test the full checkout process"
    url: "https://example.com/cart"
    context:
      - text: "The checkout process has 3 steps: shipping, payment, and confirmation"
      - text: "Credit card validation happens in real-time as the user types"
      - text: "For test purposes, use credit card number: 4111 1111 1111 1111"
    steps:
      # These steps have access to both global and test-specific context
      - "Click on the checkout button"
      - "Fill in shipping information"
      # ...
```

## Best Practices for Adding Context[​](#best-practices-for-adding-context "Direct link to Best Practices for Adding Context")

### Be Specific and Relevant[​](#be-specific-and-relevant "Direct link to Be Specific and Relevant")

Add context that directly helps with test execution:

```yaml theme={null}
context:
  - text: "The login button changes to 'Logging in...' while processing"
  - text: "Error messages appear below each form field"
  - text: "The user menu is only visible after successful login"
```

### Explain UI Components[​](#explain-ui-components "Direct link to Explain UI Components")

Describe important UI elements and their behavior:

```yaml theme={null}
context:
  - text: "The navigation uses a hamburger menu on mobile screens"
  - text: "The search bar expands when clicked"
  - text: "The product filter sidebar can be collapsed by clicking the X button"
```

### Provide Business Rules[​](#provide-business-rules "Direct link to Provide Business Rules")

Include relevant business logic or validation rules:

```yaml theme={null}
context:
  - text: "Promotional codes are case-sensitive and must be entered without spaces"
```

### Specify Test Environment Details[​](#specify-test-environment-details "Direct link to Specify Test Environment Details")

Include information about your test environment:

```yaml theme={null}
context:
  - text: "This is a staging environment and emails are not actually sent"
  - text: "The payment gateway is in test mode"
  - text: "API responses may be delayed by 1-2 seconds in this environment"
```

## When to Use Additional Context[​](#when-to-use-additional-context "Direct link to When to Use Additional Context")

Add extra context when:

1. **Your application has unique or complex behaviors** that might not be immediately obvious
2. **Test steps require specific knowledge** about the application state or business rules
3. **Handling error conditions or edge cases** that require special treatment