Troubleshooting & Examples
Troubleshooting
Q: Why are my Playwright requests missing the scenario key?
A: Ensure you call withPage(page) (or withContext(context)) before enable(). The withPage() call does not reset headers; you can set withScenarioKey() or withScenarioName() either before or after withPage(), as long as it is in effect when enable() runs.
Example:
// Recommended order in beforeEach (Playwright)
test.beforeEach(async ({ page }, testInfo) => {
interceptor.withScenarioKey('<SCENARIO-KEY>'); // can be before or after withPage
interceptor.withTestTitle(testInfo.title);
await interceptor.withPage(page).enable(); // enable after withPage
});Q: Why aren't my requests being intercepted?
A: Verify the URL patterns match your requests, the interceptor is applied in beforeEach, and stoobly-agent is running.
Example:
// Check URL pattern
const interceptor = stoobly.playwrightInterceptor({
urls: [new RegExp('https://api.example.com/.*')], // Make sure pattern matches
scenarioKey: '<SCENARIO-KEY>',
});
test.beforeEach(async ({ page }, testInfo) => {
// Ensure interceptor is applied
await interceptor.withPage(page).enable();
interceptor.withTestTitle(testInfo.title);
});
// Verify stoobly-agent is running
// stoobly-agent run --headlessQ: How do I debug interceptor issues?
A: Check the browser's network tab for Stoobly headers and verify the agent is receiving requests.
Example:
HTTP Headers Injected
The library injects these custom headers into matching HTTP requests — check the Network tab for them when debugging:
X-Stoobly-Proxy-Mode
Active intercept mode (mock/record/replay/test)
X-Stoobly-Record-Order
Recording order (append/overwrite)
X-Stoobly-Record-Policy
Recording policy (all/found/not_found)
X-Stoobly-Record-Strategy
Recording strategy (full/minimal)
X-Stoobly-Scenario-Key
Base64-encoded scenario identifier
X-Stoobly-Scenario-Name
Human-readable scenario name
X-Stoobly-Session-Id
Current session identifier
X-Stoobly-Test-Title
Current test name (auto-detected or manual)
X-Stoobly-Overwrite-Id
Present when using RecordOrder.Overwrite, first request per URL pattern only
X-Stoobly-Match-Rules
Present when using per-URL matchRules
X-Stoobly-Rewrite-Rules
Present when using per-URL rewriteRules
X-Stoobly-Public-Directory-Path
Present when using per-URL publicDirectoryPath
X-Stoobly-Response-Fixtures-Path
Present when using per-URL responseFixturesPath
Q: Why do I get "page is not defined" errors in Playwright?
A: Ensure you call withPage(page) in beforeEach before enable().
Example:
Q: How do I handle TypeScript errors?
A: The library includes TypeScript definitions. Ensure your tsconfig.json includes the library.
Example:
Complete Examples
Q: What's a complete Playwright example with recording and mocking?
A: Here's a complete example showing recording and mocking workflows with an environment variable to toggle recording mode.
Example:
Usage:
Workflow:
First run (recording): Set
STOOBLY_RECORD=trueto capture all API requests and responsesSubsequent runs (mocking): Leave
STOOBLY_RECORDunset to use recorded responses for fast, reliable testsUpdate recordings: Set
STOOBLY_RECORD=trueagain when APIs change to refresh the recorded data
Q: What's a complete Cypress example with recording and mocking?
A: Here's a complete example showing recording and mocking workflows with an environment variable to toggle recording mode.
Example:
Usage:
Workflow:
First run (recording): Set
STOOBLY_RECORD=trueto capture all API requests and responsesSubsequent runs (mocking): Leave
STOOBLY_RECORDunset to use recorded responses for fast, reliable testsUpdate recordings: Set
STOOBLY_RECORD=trueagain when APIs change to refresh the recorded data
Quick Reference
Q: What are the key methods for the interceptor?
A: Here's a quick reference of the most common interceptor methods.
Example:
Q: What constants are available?
A: Stoobly provides enums for record policies, orders, and strategies.
Example:
Last updated