Skip to content

Stoobly/stoobly-js

Repository files navigation

Stoobly Node.js library

Node.js Version npm version CI TypeScript Cypress Playwright License

The Stoobly Javascript library provides convenient access to stoobly-agent API.

Requirements

Node 18 or higher.

Installation

Install the package with:

npm install stoobly --save-dev

Usage

const { default: Stoobly } = require('stoobly');

Or using ES modules:

import Stoobly from 'stoobly';

Examples

Setting a scenario

Configures requests with origin https://docs.stoobly.com to specify a scenario. sessionId defaults to current time.

const stoobly = new Stoobly();

const sessionId = stoobly.applyScenario('<SCENARIO-KEY>', { urls: [new RegExp('https://docs.stoobly.com/.*')] });

Configures requests with origin https://docs.stoobly.com to specify a scenario. Resume a session by specifying a sessionId.

const stoobly = new Stoobly();

stoobly.applyScenario('<SCENARIO-KEY>', { urls: [new RegExp('https://docs.stoobly.com/.*')], sessionId: '<SESSION-ID>' });

Configures requests https://docs.stoobly.com/use-cases and https://docs.stoobly.com/getting-started to specify a scenario.

const stoobly = new Stoobly();

stoobly.applyScenario('<SCENARIO-KEY>', { 
    urls: [
        'https://docs.stoobly.com/use-cases',
        'https://docs.stoobly.com/getting-started'
    ]
});

Integrating with Cypress

describe('Scenario', () => {
    const stoobly = new Stoobly();

    beforeEach(() => {
        
        const urls = ['<URLS>'];

        // WARNING: if a synchronous request is used, this will cause Cypress to hang. See: https://github.com/cypress-io/cypress/issues/29566
        // Example of a synchronous request: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest_API/Synchronous_and_Asynchronous_Requests#synchronous_request
        stoobly.cypress.applyScenario('<SCENARIO-KEY>', { urls });
    });
});

Key Points:

Integrating with Playwright

describe('Scenario', () => {
    const stoobly = new Stoobly();

    beforeEach(async ({}, testInfo) => {
        const urls = ['<URLS>'];

        stoobly.playwright.setTestTitle(testInfo.title);
        stoobly.playwright.applyScenario('<SCENARIO-KEY>', { urls });
    });
});

Key Points:

  • The Stoobly instance is created once inside the describe block
  • setTestTitle() must be called in beforeEach() to update the test titles for each test because Playwright does not provide a global API to auto-detect test titles
  • Test titles are applied at request interception time

Testing

Run unit tests:

npm test

Test Cypress Integration

Run Cypress end-to-end tests:

npm run test:cypress

Test Playwright Integration

Run Playwright end-to-end tests:

npm run test:playwright

About

Javascript library for stoobly-agent

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •