For the complete documentation index, see llms.txt. This page is also available as Markdown.

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 --headless

Q: How do I debug interceptor issues?

A: Check the browser's network tab for Stoobly headers and verify the agent is receiving requests.

Example:

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:

  1. First run (recording): Set STOOBLY_RECORD=true to capture all API requests and responses

  2. Subsequent runs (mocking): Leave STOOBLY_RECORD unset to use recorded responses for fast, reliable tests

  3. Update recordings: Set STOOBLY_RECORD=true again 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:

  1. First run (recording): Set STOOBLY_RECORD=true to capture all API requests and responses

  2. Subsequent runs (mocking): Leave STOOBLY_RECORD unset to use recorded responses for fast, reliable tests

  3. Update recordings: Set STOOBLY_RECORD=true again 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