What are Contexts?
A context is a combination of:- Platforms: Operating systems (Linux, macOS, Windows)
- Browsers: Web browsers (Chrome, Firefox, Safari, WebKit)
- Config level: Default contexts for all tests
- Spec level: Contexts for all tests in a specification
- Test level: Contexts for a specific test
If no contexts are specified but a test requires a browser, Doc Detective will automatically detect and use an available browser in your current environment.
Basic Context Structure
- Firefox on Linux
- Firefox on macOS
- Firefox on Windows
Platform Options
Doc Detective supports three platform values:- linux: Linux distributions
- mac: macOS (also supports Darwin)
- windows: Windows operating systems
Platform-Only Contexts
You can specify platforms without browsers for tests that don’t require browser automation:Browser Options
Doc Detective supports four browsers:- chrome: Google Chrome
- firefox: Mozilla Firefox
- safari: Apple Safari (macOS only)
- webkit: WebKit browser engine
Simple Browser Configuration
Specify browsers as strings:Advanced Browser Configuration
For more control, use browser objects:Browser Configuration Options
Browser name:
chrome, firefox, safari, or webkitIf
true, runs the browser in headless mode (no visible window)Browser window dimensions
Browser viewport dimensions
Context Hierarchy
Contexts can be defined at multiple levels. More specific definitions override more general ones.Config-Level Contexts
Define default contexts in your.doc-detective.json configuration file:
.doc-detective.json
Spec-Level Contexts
Override config contexts for all tests in a specification:tests.spec.json
Test-Level Contexts
Override contexts for a specific test:Multiple Contexts
You can specify multiple context objects to create different combinations:- Chrome on Windows
- Chrome on Linux
- Safari on macOS
Real-World Examples
Cross-Browser Testing
Test your documentation across all major browsers on Linux:Headless CI/CD Testing
Run tests in headless mode for faster CI/CD execution:Responsive Design Testing
Test different viewport sizes:Platform-Specific Features
Test platform-specific commands:Context Resolution
When Doc Detective resolves contexts:- Starts with config-level contexts
- Overrides with spec-level contexts if present
- Overrides with test-level contexts if present
- If no contexts are defined but a browser is needed, auto-detects available browser
The resolved contexts are stored in the
contexts property of each test result. This shows exactly which contexts were used for test execution.Best Practices
Use config-level contexts for defaults
Use config-level contexts for defaults
Define your most common testing environment in your config file. This reduces duplication across test files.
.doc-detective.json
Enable headless mode in CI/CD
Enable headless mode in CI/CD
Use headless browsers in automated environments for faster execution and lower resource usage.
Test platform-specific features separately
Test platform-specific features separately
Use test-level contexts to isolate platform-specific tests. This prevents failures on unsupported platforms.
Consider your audience
Consider your audience
Prioritize testing on platforms and browsers your users actually use. You don’t need to test every combination.
Next Steps
Tests
Learn about test specifications, tests, and steps
Configuration
Configure contexts and other options
Contexts Guide
Detailed guide on working with contexts
CI/CD Integration
Set up Doc Detective in your CI/CD pipeline