Troubleshooting & Examples

Troubleshooting

Q: Why are my page test requests recorded without a scenario key?

A: withPage(page) resets interceptor state, including any scenario key previously set with withScenarioKey(). Always call withScenarioKey() after withPage() and immediately before apply() / applyRecord().

Wrong order (scenario key is wiped by withPage):

// BAD: withScenarioKey set before withPage — state is reset
interceptor.withScenarioKey('<SCENARIO-KEY>'); // set here...
interceptor.withPage(page);                    // ...wiped here
await interceptor.apply();                     // no scenario key

Correct order:

// GOOD: withScenarioKey set after withPage, right before apply
interceptor.withPage(page);
interceptor.withTestTitle(testInfo.title);
interceptor.withScenarioKey('<SCENARIO-KEY>'); // set after withPage
await interceptor.apply();                     // scenario key is present

Note: This only applies to withPage(). withContext() does not reset interceptor state, so setting the scenario key before withContext().apply() works correctly.


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:

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 apply().

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