Configuration

Configuring URL Patterns

Q: How do I specify which URLs to intercept?

A: Use the urls array with strings or regular expressions to filter which requests Stoobly intercepts.

Example:

const stoobly = new Stoobly();

// Exact URL match
const interceptor1 = stoobly.playwrightInterceptor({
  urls: ['https://api.example.com/users'],
  scenarioKey: '<SCENARIO-KEY>',
});

// Regex pattern (match all API endpoints)
const interceptor2 = stoobly.playwrightInterceptor({
  urls: [new RegExp('https://api.example.com/.*')],
  scenarioKey: '<SCENARIO-KEY>',
});

// Multiple URLs
const interceptor3 = stoobly.playwrightInterceptor({
  urls: [
    'https://api.example.com/users',
    'https://api.example.com/products',
    new RegExp('https://cdn.example.com/.*'),
  ],
  scenarioKey: '<SCENARIO-KEY>',
});

Q: How do I configure per-URL options like match rules or fixture paths?

A: Pass InterceptorUrl objects in the urls array to attach per-URL configuration such as match rules, rewrite rules, a public directory path, or a response fixtures path.

InterceptorUrl shape:

Example:

Use InterceptorUrl when:

  1. You need different match rules for specific endpoints

  2. You want to serve static fixture files for certain URLs

  3. You need rewrite rules applied to a subset of intercepted URLs


Q: How do I change the intercepted URLs dynamically?

A: Pass a new urls array to the apply() method to update which URLs are intercepted.

Example:


Scenarios and Sessions

Q: How do I specify a scenario for my tests?

A: Use scenarioKey or scenarioName in the interceptor options to associate requests with a scenario.

Example:

Q: How do I change the scenario dynamically?

A: Use withScenarioKey() or withScenarioName() to update the scenario.

Example:

Q: What is a session ID and how do I use it?

A: A session ID groups requests together within a scenario. It defaults to the current timestamp but can be customized for test reproducibility.

Example:


Recording Configuration

Q: What record policies are available?

A: Stoobly supports three record policies: All (record everything), Found (record only if request exists), and NotFound (record only new requests).

Example:

Q: What's the difference between record orders?

A: Overwrite replaces existing requests with the same signature, while Append always creates new request records.

Example:

Note: Overwrite is sent only once per URL pattern per session. Subsequent requests to the same URL pattern use Append behavior. Each URL pattern is tracked independently, so multiple patterns can each receive one overwrite.

Q: What record strategies are available?

A: Stoobly supports Full (record complete request/response) and Minimal (record only essential data).

Example:

Q: How do I change record settings dynamically?

A: Use withRecordPolicy(), withRecordOrder(), and withRecordStrategy() methods.

Example:


Controlling Interception

Q: How do I stop recording requests?

A: Use clearRecord() to stop recording while keeping the interceptor active for mocking.

Example:

Q: How do I completely remove the interceptor?

A: Use clear() to remove all interception and clear all headers.

Example:

Q: What's the difference between clear() and clearRecord()?

A: clearRecord() stops recording but keeps mocking active, while clear() removes all interception.

Example:


Advanced Configuration

Q: How do I set a custom Stoobly UI URL?

A: Pass the UI URL to the Stoobly constructor if your agent is running on a different port or host.

Example:

Q: How do I use test titles for request grouping?

A: Set test titles using withTestTitle() to group requests by test name in the Stoobly UI.

Example:

Q: Can I use the interceptor without a test framework?

A: Yes, use the generic interceptor() method for vanilla JavaScript applications.

Example:

Last updated