The Stoobly Javascript library provides convenient access to stoobly-agent API.
Node 18 or higher.
Install the package with:
npm install stoobly --save-devconst { default: Stoobly } = require('stoobly');Or using ES modules:
import Stoobly from 'stoobly';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'
]
});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:
- The Stoobly instance is created once inside the
describeblock - Test titles are automatically detected at request interception time for each test
stoobly.cypress.applyScenariocannot be applied inbeforeAllbecause it usescy.intercept.cy.interceptgets reset before every test. See: https://docs.cypress.io/api/commands/intercept#:~:text=All%20intercepts%20are%20automatically%20cleared%20before%20every%20test.
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
describeblock setTestTitle()must be called inbeforeEach()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
Run unit tests:
npm testRun Cypress end-to-end tests:
npm run test:cypressRun Playwright end-to-end tests:
npm run test:playwright