Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

447
Views
Is there a way to intercept the response of a HTTP request made from the client side in Cypress?

Suppose I have a button that calls a function making a HTTP request, that responds with a the value of a token. After using Cypress to click this button, how can I intercept the response of the HTTP request being made from clicking the button to extract this token?

I have looked into the official Cypress documentation on the intercept method, as well as this article: https://egghead.io/blog/intercepting-network-requests-in-cypress but from what I understand, Cypress is intercepting a HTTP request called directly from the test file, and not the function being called after clicking the client-side button.

It would be much appreciated if one of you knowledgable folks can clarify how to use the intercept method.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have it backwards - Cypress intercepts requests from the app, but it cannot intercept requests from the test.

When your test clicks the button, it fires a click event in the app, which then sends the request out and this can be intercepted.

Here's a simple example

it('intercepts request from app', () => {

  cy.intercept('**/guides/guides/network-requests').as('link-intercepted')

  cy.visit('https://docs.cypress.io/api/commands/intercept')

  cy.contains('a', 'Network Requests').click()  // fire event
                                                // which triggers request from app

  cy.wait('@link-intercepted')
  cy.contains('h1', 'Network Requests')  // heading of the new page
})

But a request from the test fails

it('cannot catch requests from test', () => {

  cy.intercept('**/guides/guides/network-requests').as('link-intercepted')
  cy.visit('https://docs.cypress.io/api/commands/intercept')

  // fire request from the test
  cy.request('https://docs.cypress.io/guides/guides/network-requests')

  cy.wait('@link-intercepted')  // waits 5 seconds and fails

})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!