QA Interview Hub · Knowledge base · Quizzes · Українська

Cypress › API testing

What limits does Cypress have for API testing and when should you take another tool?

Cypress was built for UI tests, so even a pure API test starts a browser and runs slower than a plain HTTP client in Node. Cross-machine parallelism is built in only through Cypress Cloud, load comes from a single browser process, and there is no built-in WebSocket command. For a large standalone API suite, Playwright request, Postman with Newman or Supertest fit better, and k6, Gatling or JMeter for load.

Cypress · API testing

A team has three hundred API tests in Cypress and wants parallelisation and load testing. Is it the same tool?

Cypress was created as a tool for UI tests, and cy.request appeared as a helper. In time full API suites grew out of it, and it matters to know where that fits and where the tool works against itself. The question “when to take another tool” checks that you understand trade-offs, not only syntax.

How it works and why

The limits follow from the design. Cypress runs tests in a built-in browser, so even a pure API test starts a browser and runs in its environment: this is slower than a plain HTTP client in Node. Parallel runs across machines are built into Cypress Cloud (the --parallel --record flags); without it, specs have to be split between CI jobs by hand or with a plugin; the details are in the parallelisation lesson. Load comes from one browser process, not thousands of virtual users, so k6, Gatling and JMeter exist for that. WebSocket has no built-in command, and cy.intercept does not show its frames.

Where Cypress for APIs fits

Cypress is enough

The API serves UI tests

Data setup, login, checking what was stored after a UI action, a few direct checks. One stack, one team.

Better another tool

A separate API suite, load

Hundreds of standalone API tests, load scenarios, WebSocket, contract tests between teams.

Figure 1. The fork is not about the tool’s quality but about the role of API tests in the project.

Example: WebSocket through Node

There is no built-in command for WebSocket, but cy.task runs in Node, where the ws library exists. This is a working workaround, and also a signal: if such logic becomes the main one, a tool where it is native is handier.

// WebSocket in Cypress: no built-in command, so go through Node
// cypress.config.ts
import WebSocket from 'ws';

setupNodeEvents(on) {
  on('task', {
    wsEcho(msg: string) {
      return new Promise((resolve, reject) => {
        const ws = new WebSocket('ws://localhost:8080');
        ws.on('open', () => ws.send(msg));
        ws.on('message', (m) => { ws.close(); resolve(m.toString()); });
        ws.on('error', reject);
      });
    },
  });
}

// test
cy.task('wsEcho', 'ping').should('eq', 'ping');

Request bodies, by contrast, are not a problem: the form option gives application/x-www-form-urlencoded, and a FormData body is sent as multipart/form-data, so a file upload needs no plugin. The friction is elsewhere: every such test still starts a browser.

Limits and alternatives

  • Postman/Newman: collections handy for manual exploration and running in CI, good for testers without code.
  • Playwright request: no browser, parallel through workers, an HTML report. WebSocket can be listened to through page.on('websocket') or mocked through routeWebSocket.
  • Supertest, REST Assured: tests next to the backend code, in its language.
  • k6, JMeter, Gatling: load. Neither Cypress nor Playwright is meant for it.

For a more convenient display of requests in the Command Log there is the cypress-plugin-api plugin (check Cypress 16 compatibility). It changes the display, not the limits of the tool itself.

Typical mistakes

  • Keeping hundreds of standalone API tests in Cypress, paying for a browser they do not need.
  • Trying to load the system with a cy.request loop: that is not a load test.
  • Taking another tool “because it is trendy” when API tests only prepare data for the UI.
  • Assuming cy.intercept will check WebSocket.

Check yourself

Why is load testing not done with a cy.request loop?

Answer

The requests go from one process inside a test, with no load distribution, user models or percentile metrics. k6, JMeter and Gatling exist for that.

In which case is Cypress for API tests fully justified?

Answer

When API tests mostly serve UI tests (data setup, login, confirming what was stored) and the team wants one stack.

In an interview. Junior: Cypress is fine for API tests, but without Cloud there is no built-in parallelisation across machines, WebSocket is not tested directly, you cannot check load with it, and even for an API a browser starts. For many standalone API tests I take Postman with Newman or Playwright request. Middle/Senior: I look at the role of API tests: when they serve the UI suite I keep Cypress and one stack; when it is a separate large suite I move to a tool without a browser and with parallelisation. I give load to k6 or Gatling and keep contracts between teams separate.

More articles in this chapter