How to intercept API calls with cy.intercept() method in Cypress 6

Поделиться
HTML-код
  • Опубликовано: 29 окт 2024
  • This lesson is a part of my Udemy class: Cypress from Zero to Hero.
    Link to the class: www.udemy.com/...
    In this lesson, you will learn how to use the new method cy.intercept() in Cypress 6 to intercept API requests and responses and provide sub for request or response body during API call.

Комментарии • 30

  • @Rodrigossilvestre
    @Rodrigossilvestre 3 года назад +4

    it's so good when i'm having a hard time understanding a topic and i end up finding a video like this, congratulations man, you clearly show how the intercept works in a nice way, GREAT VIDEO!

  • @studywith-grace
    @studywith-grace 2 года назад +1

    Highly recommend this instructor's full course on Udemy 😊

  • @kaname223
    @kaname223 2 года назад

    Great video , how do you intercept dynamic request payload ? example , every time you add cart item , the request array values changes (the array include more than 200 value

  • @ankitkumar-ih8qo
    @ankitkumar-ih8qo 3 года назад +1

    I want to test for POST data (you take example as registration for like email, password), to send data to "backend i.e in database", Could you please suggest me, How can I do that ?

  • @rcbchowdarytumati1224
    @rcbchowdarytumati1224 3 года назад +1

    Great video.
    Could you please do videos on JavaScript for javascript

  • @sayon1995
    @sayon1995 3 года назад +2

    Nice videos dude, i love them!

  • @marcellifaria
    @marcellifaria 11 месяцев назад

    How can we modify response status to mock a behavior ?

  • @mateusvitorino
    @mateusvitorino 3 года назад

    When do you used this command (intercept) with POST methods, it sends the request to your database? Or the request is just intercept?

    • @artembondar6577
      @artembondar6577  3 года назад +1

      Depends on how you configure it. You can intercept the request and provide own response, in this case it will not send data to backend. Or you can intercept response from server and do something with it before it will be processed by browser

  • @Ashokkumarg8
    @Ashokkumarg8 3 года назад

    I perform a operation in UI and during that time list of api calls would be loaded into Network tab. How can I verify those API Status is 200? Would intercept work?

    • @artembondar6577
      @artembondar6577  3 года назад

      Yes it will. In response handler get the response and assert status

    • @Ashokkumarg8
      @Ashokkumarg8 3 года назад

      @@artembondar6577 any reference

    • @artembondar6577
      @artembondar6577  3 года назад +1

      @@Ashokkumarg8 docs.cypress.io/api/commands/intercept#Using-the-yielded-object

    • @Ashokkumarg8
      @Ashokkumarg8 3 года назад

      @@artembondar6577 I tried with same for GET, POST call. But received the error like No requests were created. I have done with cy.intercept with full url, call name, body etc.,

    • @artembondar6577
      @artembondar6577  3 года назад +1

      @@Ashokkumarg8 Well, it means you did something wrong. Probably you didn't match the URL that you were going to intercept. All need to debug.

  • @ravisaikota5789
    @ravisaikota5789 3 года назад

    Hi, how to use bearer token? my application has token to get the data. how work with that?

    • @artembondar6577
      @artembondar6577  3 года назад +1

      This token needed to establish connection to your API. You should put this token in the header of API request with name "Authorization"

  • @ppp.1334
    @ppp.1334 2 года назад

    Hi Artem, maybe its time to publish something '@New'

    • @artembondar6577
      @artembondar6577  11 месяцев назад

      I regularly publish something new on Udemy. As well as keeping it up to date.

    • @ppp.1334
      @ppp.1334 11 месяцев назад

      @@artembondar6577 a added this comment year ago 🙂
      Cheers

  • @ZornStolz
    @ZornStolz 2 года назад

    hero

  • @hajune7558
    @hajune7558 3 года назад

    How to reuse fixture json file? :D

    • @artembondar6577
      @artembondar6577  3 года назад

      cy.fixture('yourFile.json').as('myFile')
      Then you can call cy.get('myFile'). But it's redundant. You can call cy.fixture() whenever you need your fixture file

  • @bohdanromanovich4912
    @bohdanromanovich4912 2 года назад

    When I search cy.intercept() in youtube, removing some old methods (I don't now how they work also) and raplacing it with a new method without any explanation is not what i want to see)) confusing video