Skip to content

Commit fd69934

Browse files
Centralize test configuration settings
Created central config file (config/test-config.ts) to eliminate hardcoded values and provide single source of truth for all test settings. New Config Categories: - APP_URLS: Application URLs (Angular, API, IdentityServer) - TIMEOUTS: Standard timeouts (30s, 5s, navigation, validation, etc.) - VIEWPORTS: Common viewport sizes (mobile, tablet, laptop, desktop) - VISUAL_THRESHOLDS: Max pixel differences for visual regression tests - SELECTORS: Frequently used CSS selectors - TEXT_PATTERNS: Common regex patterns for text matching - PERFORMANCE: Performance thresholds (memory, load times, etc.) - FEATURES: Feature flags to enable/disable test behaviors - DATA_LIMITS: Test data constraints (max lengths, values, etc.) Benefits: - Single source of truth - change in one place affects all tests - Better maintainability - no more hunting for hardcoded values - Consistency - all tests use same timeouts, viewports, thresholds - Type safety - TypeScript ensures correct usage - Documentation - centralized README explains usage Updated: - playwright.config.ts: Now uses APP_URLS, TIMEOUTS, and VIEWPORTS - config/README.md: Usage examples and documentation Next Steps: - Gradually refactor existing tests to use centralized config - This improves test quality and reduces maintenance burden
1 parent c20d0db commit fd69934

3 files changed

Lines changed: 256 additions & 103 deletions

File tree

config/README.md

Lines changed: 64 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,77 @@
1-
# Configuration
2-
3-
Configuration files for test execution and environment settings.
4-
5-
## Purpose
6-
7-
Configuration files provide:
8-
- Test user credentials for different roles
9-
- Environment-specific URLs (dev, staging, production)
10-
- API endpoint configurations
11-
- Test execution parameters
12-
13-
## Planned Files
14-
15-
### `test-users.json`
16-
17-
Test account credentials for all user roles:
18-
19-
```json
20-
{
21-
"employee": {
22-
"username": "employee1",
23-
"password": "Pa$$word123",
24-
"role": "Employee",
25-
"permissions": ["read"]
26-
},
27-
"manager": {
28-
"username": "ashtyn1",
29-
"password": "Pa$$word123",
30-
"role": "Manager",
31-
"permissions": ["read", "write"]
32-
},
33-
"hradmin": {
34-
"username": "admin1",
35-
"password": "Pa$$word123",
36-
"role": "HRAdmin",
37-
"permissions": ["read", "write", "delete", "admin"]
38-
}
39-
}
40-
```
1+
# Test Configuration
412

42-
### `environments.json`
43-
44-
Environment-specific URLs and configurations:
45-
46-
```json
47-
{
48-
"development": {
49-
"angularUrl": "http://localhost:4200",
50-
"apiUrl": "https://localhost:44378",
51-
"identityServerUrl": "https://sts.skoruba.local",
52-
"timeout": 30000
53-
},
54-
"staging": {
55-
"angularUrl": "https://staging.example.com",
56-
"apiUrl": "https://api-staging.example.com",
57-
"identityServerUrl": "https://sts-staging.example.com",
58-
"timeout": 60000
59-
}
60-
}
61-
```
3+
This directory contains centralized configuration files for the Playwright test suite.
4+
5+
## Files
6+
7+
### test-config.ts
8+
9+
Central configuration for all test settings. Import from this file instead of hardcoding values.
6210

63-
### `api-endpoints.json`
64-
65-
API endpoint definitions:
66-
67-
```json
68-
{
69-
"employees": {
70-
"list": "/api/v1/employees",
71-
"detail": "/api/v1/employees/{id}",
72-
"create": "/api/v1/employees",
73-
"update": "/api/v1/employees/{id}",
74-
"delete": "/api/v1/employees/{id}"
75-
},
76-
"departments": {
77-
"list": "/api/v1/departments",
78-
"detail": "/api/v1/departments/{id}",
79-
"create": "/api/v1/departments",
80-
"update": "/api/v1/departments/{id}",
81-
"delete": "/api/v1/departments/{id}"
82-
}
83-
}
11+
**Benefits:**
12+
- Single source of truth for all configuration
13+
- Easy to update settings across all tests
14+
- Better maintainability
15+
- Consistent values across test suites
16+
17+
## Usage Examples
18+
19+
### Importing Configuration
20+
21+
```typescript
22+
import {
23+
APP_URLS,
24+
TIMEOUTS,
25+
VIEWPORTS,
26+
SELECTORS,
27+
TEXT_PATTERNS,
28+
VISUAL_THRESHOLDS,
29+
PERFORMANCE,
30+
} from '../config/test-config';
8431
```
8532

86-
## Usage Example
33+
### Using URLs
8734

8835
```typescript
89-
import { test } from '@playwright/test';
90-
import testUsers from '../config/test-users.json';
91-
import environments from '../config/environments.json';
36+
// ❌ Before (hardcoded)
37+
await page.goto('http://localhost:4200/dashboard');
9238

93-
const env = environments.development;
94-
const managerUser = testUsers.manager;
39+
// ✅ After (centralized)
40+
import { APP_URLS, getUrl } from '../config/test-config';
41+
await page.goto(getUrl('/dashboard'));
42+
```
43+
44+
### Using Timeouts
45+
46+
```typescript
47+
// ❌ Before (hardcoded)
48+
await page.waitForTimeout(1000);
9549

96-
test('Login as manager', async ({ page }) => {
97-
await page.goto(env.angularUrl);
98-
// Use managerUser.username and managerUser.password
99-
});
50+
// ✅ After (centralized)
51+
import { TIMEOUTS } from '../config/test-config';
52+
await page.waitForTimeout(TIMEOUTS.afterNavigation);
10053
```
10154

102-
## Security Note
55+
### Using Viewports
56+
57+
```typescript
58+
// ❌ Before (hardcoded)
59+
await page.setViewportSize({ width: 375, height: 667 });
60+
61+
// ✅ After (centralized)
62+
import { VIEWPORTS } from '../config/test-config';
63+
await page.setViewportSize(VIEWPORTS.mobile);
64+
```
10365

104-
⚠️ **Important:** Never commit real production credentials to this directory. Use environment variables or secrets management for production environments.
66+
## Configuration Categories
10567

106-
## Status
68+
- **APP_URLS**: Application URLs
69+
- **TIMEOUTS**: Standard timeouts (30s, 5s, etc.)
70+
- **VIEWPORTS**: Mobile, tablet, laptop, desktop sizes
71+
- **VISUAL_THRESHOLDS**: Max pixel differences for visual tests
72+
- **SELECTORS**: Common CSS selectors
73+
- **TEXT_PATTERNS**: Regular expressions for text matching
74+
- **PERFORMANCE**: Performance thresholds
75+
- **FEATURES**: Feature flags
10776

108-
**Not yet implemented** - See [IMPLEMENTATION_PLAN.md](../docs/IMPLEMENTATION_PLAN.md) Phase 1, Week 1
77+
See test-config.ts for complete documentation.

config/test-config.ts

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
/**
2+
* Centralized Test Configuration
3+
*
4+
* This file contains all configurable settings used across test suites.
5+
* Modify these values in one place to affect all tests.
6+
*/
7+
8+
/**
9+
* Application URLs
10+
*/
11+
export const APP_URLS = {
12+
angular: 'http://localhost:4200',
13+
api: 'https://localhost:44378/api/v1',
14+
identityServer: 'https://sts.skoruba.local',
15+
} as const;
16+
17+
/**
18+
* Test Timeouts (in milliseconds)
19+
*/
20+
export const TIMEOUTS = {
21+
// Standard timeout for most operations
22+
standard: 30000,
23+
24+
// Short timeout for quick checks
25+
short: 5000,
26+
27+
// Long timeout for slow operations (e.g., large dataset loading)
28+
long: 60000,
29+
30+
// Wait after page navigation
31+
afterNavigation: 1000,
32+
33+
// Wait for form to open
34+
formOpen: 1000,
35+
36+
// Wait for validation to appear
37+
validation: 500,
38+
39+
// Wait for dynamic content to load
40+
dynamicContent: 2000,
41+
42+
// Wait for charts to render
43+
chartRender: 2000,
44+
} as const;
45+
46+
/**
47+
* Viewport Sizes
48+
*/
49+
export const VIEWPORTS = {
50+
mobile: { width: 375, height: 667 },
51+
tablet: { width: 768, height: 1024 },
52+
laptop: { width: 1366, height: 768 },
53+
desktop: { width: 1920, height: 1080 },
54+
} as const;
55+
56+
/**
57+
* Visual Regression Thresholds
58+
*/
59+
export const VISUAL_THRESHOLDS = {
60+
// Maximum pixel difference for full page screenshots
61+
fullPage: 100,
62+
63+
// Maximum pixel difference for component screenshots
64+
component: 50,
65+
66+
// Maximum pixel difference for small elements
67+
element: 30,
68+
} as const;
69+
70+
/**
71+
* Common Selectors
72+
*
73+
* Frequently used CSS selectors and patterns
74+
*/
75+
export const SELECTORS = {
76+
// Buttons
77+
createButton: 'button',
78+
submitButton: 'button[type="submit"], button',
79+
cancelButton: 'button',
80+
81+
// Forms
82+
formDialog: 'form, mat-dialog',
83+
84+
// Validation
85+
errorMessage: 'mat-error, .mat-mdc-form-field-error, .mat-error',
86+
87+
// Navigation
88+
sidenav: 'mat-sidenav, .sidenav, nav, aside',
89+
userMenu: 'button mat-icon:has-text("account_circle")',
90+
91+
// Tables
92+
table: 'table, mat-table',
93+
tableRow: 'tr, mat-row',
94+
95+
// Charts
96+
chart: 'canvas, svg',
97+
} as const;
98+
99+
/**
100+
* Common Text Patterns (Regular Expressions)
101+
*/
102+
export const TEXT_PATTERNS = {
103+
createButton: /create|add.*employee|new/i,
104+
submitButton: /create|submit|save/i,
105+
cancelButton: /cancel|close/i,
106+
dashboard: /dashboard|home/i,
107+
emailError: /email|valid|format|@/i,
108+
requiredError: /required|empty|invalid/i,
109+
lengthError: /length|max|characters/i,
110+
} as const;
111+
112+
/**
113+
* Test Data Limits
114+
*/
115+
export const DATA_LIMITS = {
116+
// Maximum length for text fields
117+
maxNameLength: 200,
118+
119+
// Maximum salary value to test
120+
maxSalary: 999999999999999,
121+
122+
// Page sizes for pagination tests
123+
pageSizes: [10, 25, 50, 100],
124+
} as const;
125+
126+
/**
127+
* Performance Thresholds
128+
*/
129+
export const PERFORMANCE = {
130+
// Maximum memory usage in bytes (100 MB)
131+
maxMemoryUsage: 100 * 1048576,
132+
133+
// Maximum page change time in ms
134+
maxPageChangeTime: 2000,
135+
136+
// Maximum render time in ms
137+
maxRenderTime: 3000,
138+
139+
// Maximum search time in ms
140+
maxSearchTime: 2000,
141+
142+
// Maximum sort time in ms
143+
maxSortTime: 2000,
144+
145+
// Maximum filter time in ms
146+
maxFilterTime: 2000,
147+
148+
// Maximum scroll time in ms
149+
maxScrollTime: 1000,
150+
} as const;
151+
152+
/**
153+
* Feature Flags / Test Toggles
154+
*
155+
* Enable/disable certain test behaviors
156+
*/
157+
export const FEATURES = {
158+
// Whether to skip tests that require API authentication
159+
skipApiAuthTests: true,
160+
161+
// Whether to run visual regression tests
162+
runVisualTests: true,
163+
164+
// Whether to run performance tests
165+
runPerformanceTests: true,
166+
167+
// Whether to run accessibility tests
168+
runA11yTests: true,
169+
} as const;
170+
171+
/**
172+
* Helper function to get full URL
173+
*/
174+
export function getUrl(path: string): string {
175+
return `${APP_URLS.angular}${path}`;
176+
}
177+
178+
/**
179+
* Helper function to get API URL
180+
*/
181+
export function getApiUrl(endpoint: string): string {
182+
return `${APP_URLS.api}${endpoint}`;
183+
}

0 commit comments

Comments
 (0)