Cypress Plugin API is a tool for enhancing API testing within the Cypress test runner by providing a user interface similar to Postman. It extends the standard `cy.request()` command with `cy.api()`, which visually logs details about API calls, including URLs, headers, request/response bodies, and cookies, directly into the Cypress App UI. These details are viewable through time-travel snapshots. Key features include JSON data object/array folding, HTTP method color coding, response size calculation, and options for sensitive data masking (like credentials) and integrating API calls seamlessly into UI test flows using `snapshotOnly` mode. The plugin currently maintains version `2.11.2`, released on July 14, 2024, with a consistent cadence of bug fixes and minor feature additions. It ships with TypeScript types to provide a better development experience.
npm install cypress-plugin-apiVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up `cypress-plugin-api` in `cypress.config.ts`, importing it, and using `cy.api()` for GET and POST requests. It also showcases `hideCredentials` and `snapshotOnly` environmental options.
Upgrade your Cypress installation to version 10 or higher (e.g., `npm install cypress@latest`).
Ensure `import 'cypress-plugin-api'` (ESM) or `require('cypress-plugin-api')` (CommonJS) is present in your support file (e.g., `cypress/support/e2e.ts`).Set `env: { requestMode: true }` in your `cypress.config.{js,ts}` file or per-test configuration.Carefully define all fields you wish to hide in the `hideCredentialsOptions` array if `hideCredentials: true` is also enabled, as it will take precedence over defaults.
Ensure your `tsconfig.json` properly includes the plugin's types (e.g., in `compilerOptions.types` or by including `cypress-plugin-api` in `typeRoots`). If using explicit reference directives, ensure `/// <reference types="cypress-plugin-api" />` is present.
Add `import 'cypress-plugin-api'` to your `cypress/support/e2e.ts` (or `.js`) file.
Ensure the package is installed via `npm install cypress-plugin-api` or `yarn add cypress-plugin-api`. Check your `cypress/support/e2e.{js,ts}` path and `tsconfig.json` if applicable.Verify that `cypress-plugin-api` is listed in the `types` array of your `tsconfig.json` (e.g., `"types": ["cypress", "cypress-plugin-api"]`) or that `/// <reference types="cypress-plugin-api" />` is in a relevant `.d.ts` file or `cypress/support/e2e.ts`.