viewpoint-test-macros
Procedural macros for the Viewpoint test framework, providing the #[viewpoint::test] attribute macro for convenient test setup.
This crate is part of the Viewpoint browser automation framework.
Features
- Automatic Setup: Browser, context, and page are set up before the test
- Automatic Cleanup: Resources are cleaned up after the test completes
- Fixture Injection: Request fixtures by parameter type (Page, BrowserContext, Browser)
- Fixture Scoping: Share browsers/contexts across tests for performance
- Configuration: Customize headless mode, timeouts, and more
Installation
This crate is typically used through viewpoint-test:
[]
= "0.2"
= { = "1", = ["macros", "rt-multi-thread"] }
Quick Start
use ;
async
The macro automatically:
- Creates a
TestHarness - Provides the requested fixtures (
page,context,browser) - Handles cleanup on test completion
Fixture Parameters
Request different fixtures by changing the parameter types:
use test;
use ;
// Get just the page (most common)
async
// Get page and context
async
// Get page, context, and browser
async
Configuration Options
Configure the test with attribute arguments:
use test;
use Page;
// Run in headed mode (visible browser)
async
// Custom timeout (in milliseconds)
async
Fixture Scoping
Share browsers/contexts across tests for better performance:
Browser Scope
Share a browser across multiple tests (each test gets a fresh context and page):
use test;
use ;
use OnceLock;
// Define a shared browser
static BROWSER: = new;
async
async
async
Context Scope
Share a context across tests (each test gets a fresh page, but shares cookies/state):
use test;
use ;
async
async
All Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
headless |
bool | true |
Run browser in headless mode |
timeout |
integer | 30000 | Default timeout in milliseconds |
scope |
string | - | Fixture scope: "browser" or "context" |
browser |
string | - | Function name returning shared browser (required when scope = "browser") |
context |
string | - | Function name returning shared context (required when scope = "context") |
When to Use TestHarness Instead
The macro is convenient but TestHarness offers more control:
- When you need to configure the browser context with specific options
- When you need to set up network interception before navigation
- When you want more explicit control over setup and teardown
- When you need to handle setup failures differently
use TestHarness;
async
License
MIT