aboutsummaryrefslogtreecommitdiff
path: root/tests/integration/README.md
blob: 99f74a68333a04bfe8b4a7560c229ea39561d435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Integration Tests with Selenium

This directory contains Selenium-based integration tests for the web application.

## Setup

1. Install Python dependencies:
```bash
pip install -r requirements-test.txt
```

2. Chrome browser must be installed (ChromeDriver will be downloaded automatically)

## Running Tests

### Run all tests:
```bash
pytest
```

### Run specific test categories:
```bash
# Smoke tests only
pytest -m smoke

# UI interaction tests
pytest -m ui

# Network tests
pytest -m network
```

### Run in headless mode:
```bash
$env:HEADLESS="1"; pytest
```

### Run with verbose output:
```bash
pytest -v
```

### Run specific test file:
```bash
pytest tests/integration/test_smoke.py
```

### Run specific test function:
```bash
pytest tests/integration/test_smoke.py::test_page_loads
```

## How It Works

The test suite automatically:
1. Starts a local HTTP server on a free port
2. Serves the application from the `ggj26/` directory
3. Runs tests against the local server
4. Shuts down the server when tests complete

This ensures JavaScript features requiring a web server (like CORS, modules, etc.) work correctly.

## Environment Variables

- `APP_URL`: Override the automatic HTTP server to test against an external URL
  ```bash
  $env:APP_URL="http://localhost:8080"; pytest
  ```

- `HEADLESS`: Set to "1" to run tests in headless mode (no visible browser)
  ```bash
  $env:HEADLESS="1"; pytest
  ```

## Test Structure

- `conftest.py`: Pytest fixtures and configuration
  - `http_server`: Starts local HTTP server (session-scoped)
  - `base_url`: URL for the application
  - `driver`: Selenium WebDriver instance
  - `app`: Loads the application
  - `ready_app`: Loads app and waits for it to be ready
  - `wait`: WebDriverWait helper

- `test_smoke.py`: Basic smoke tests to verify core functionality
- `test_ui.py`: UI interaction tests (clicks, keyboard, mouse)

## Writing New Tests

Example test:
```python
import pytest
from selenium.webdriver.common.by import By

@pytest.mark.smoke
def test_my_feature(app):
    """Test description."""
    element = app.find_element(By.ID, "my-element")
    assert element.is_displayed()
```

## Debugging

### View browser during test execution:
Don't set `HEADLESS=1` - tests will run with visible browser.

### Add breakpoints:
```python
import pdb; pdb.set_trace()
```

### Take screenshots on failure:
```python
def test_something(app):
    try:
        # test code
        pass
    except:
        app.save_screenshot("failure.png")
        raise
```

### Check console logs:
```python
logs = app.get_log("browser")
print(logs)
```