Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[proposal] Lightweight API journeys DSL #900

Open
vigneshshanmugam opened this issue Mar 1, 2024 · 1 comment
Open

[proposal] Lightweight API journeys DSL #900

vigneshshanmugam opened this issue Mar 1, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@vigneshshanmugam
Copy link
Member

vigneshshanmugam commented Mar 1, 2024

Summary

Introduce a way to run Lightweight API based journeys that does not involve launching browsers for every run, instead rely on the APIRequest API provided by Playwright core to do Web API testing.

Proposal

The agent will introduce a new API for registering and running these API based checks.

DSL

type APIJourneyOptions = {
  name: string;
  id?: string;
  tags?: string[];
};

type APIJourneyCallback = (options: {
  request: APIRequestContext;
  params: Params;
}) => void;

export { apijourney }

Usage

Users would import this API and configure the tests.

import { apijourney, monitor, expect } from "@elastic/synthetics";

apijourney('test example.com', async ({ request, params }) => {
 // monitor configurations would still work as usual
 monitor.use({ schedule: 10, locations: [ "us_east1"] });

  const resp = await request.get('https://example.com/api/getText', {
    params: { id: params.id },
  });
  const data = resp.json();
  expect(data).toEqual({ text: 'Hello, World!' });
});

difference with journey API and request context exposed.

  • Does not require spinning a new browser instance, instead each api journey will create a separate APIRequestContext which have its own cookie storage.
  • The request object exposed by the browser journey API does share the same context configurations meaning the cookies will be shared based between API requests and Page requests.

Addresses #137

@vigneshshanmugam vigneshshanmugam added the enhancement New feature or request label Mar 1, 2024
@jasonwhetton
Copy link

Eagerly awaiting this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants