---
title: "E2E Tests"
description: "End-to-end testing for TraceRTM"
keywords: [e2e, end-to-end, testing, playwright, selenium]
---

# E2E Tests

End-to-end testing for complete user workflows.

## E2E Test Framework

### Playwright Setup

```python
import pytest
from playwright.async_api import async_playwright

@pytest.fixture
async def browser():
    """Browser fixture."""
    async with async_playwright() as p:
        browser = await p.chromium.launch()
        yield browser
        await browser.close()

@pytest.fixture
async def page(browser):
    """Page fixture."""
    page = await browser.new_page()
    yield page
    await page.close()
```

## Test Scenarios

### User Workflow

```python
@pytest.mark.asyncio
async def test_create_item_workflow(page):
    """Test complete item creation workflow."""
    # Navigate to app
    await page.goto("http://localhost:3000")
    
    # Login
    await page.fill('input[name="email"]', "test@example.com")
    await page.fill('input[name="password"]', "password")
    await page.click('button[type="submit"]')
    
    # Create item
    await page.click('button:has-text("New Item")')
    await page.fill('input[name="title"]', "Test Item")
    await page.select_option('select[name="view"]', "requirements")
    await page.click('button:has-text("Create")')
    
    # Verify item created
    await page.wait_for_selector('text=Test Item')
    assert await page.is_visible('text=Test Item')
```

## API E2E Tests

### Complete API Flow

```python
def test_complete_traceability_flow():
    """Test complete traceability workflow."""
    # Create project
    project = client.post("/api/v1/projects", json={
        "name": "Test Project"
    }).json()
    
    # Create requirement
    req = client.post("/api/v1/items", json={
        "title": "Requirement",
        "view": "requirements",
        "project_id": project["id"]
    }).json()
    
    # Create test case
    test = client.post("/api/v1/items", json={
        "title": "Test Case",
        "view": "test-cases",
        "project_id": project["id"]
    }).json()
    
    # Create link
    link = client.post("/api/v1/links", json={
        "source_id": req["id"],
        "target_id": test["id"],
        "type": "verified_by"
    }).json()
    
    # Verify traceability
    impact = client.get(f"/api/v1/analysis/impact/{req['id']}").json()
    assert test["id"] in [item["id"] for item in impact["affected_items"]]
```

## Test Data

### Fixtures for E2E

```python
@pytest.fixture
def test_project():
    """Create test project."""
    response = client.post("/api/v1/projects", json={
        "name": "E2E Test Project"
    })
    return response.json()

@pytest.fixture
def test_items(test_project):
    """Create test items."""
    items = []
    for title in ["Req 1", "Req 2", "Test 1"]:
        response = client.post("/api/v1/items", json={
            "title": title,
            "view": "requirements" if "Req" in title else "test-cases",
            "project_id": test_project["id"]
        })
        items.append(response.json())
    return items
```

## Best Practices

### 1. Clean Up Test Data

```python
@pytest.fixture(autouse=True)
def cleanup():
    """Clean up after tests."""
    yield
    # Delete test data
    client.delete(f"/api/v1/projects/{test_project_id}")
```

### 2. Use Page Objects

```python
class ItemPage:
    def __init__(self, page):
        self.page = page
    
    async def create_item(self, title: str, view: str):
        await self.page.click('button:has-text("New Item")')
        await self.page.fill('input[name="title"]', title)
        await self.page.select_option('select[name="view"]', view)
        await self.page.click('button:has-text("Create")')
```

## Related Documentation

- [Unit Tests](./04a-unit-tests) - Unit testing
- [Integration Tests](./04b-integration-tests) - Integration testing
