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.
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!
Happy to hear that!
Highly recommend this instructor's full course on Udemy 😊
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
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 ?
Great video.
Could you please do videos on JavaScript for javascript
I am not a JS expert so probaply not
Nice videos dude, i love them!
Thanks man! :)
How can we modify response status to mock a behavior ?
When do you used this command (intercept) with POST methods, it sends the request to your database? Or the request is just intercept?
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
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?
Yes it will. In response handler get the response and assert status
@@artembondar6577 any reference
@@Ashokkumarg8 docs.cypress.io/api/commands/intercept#Using-the-yielded-object
@@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.,
@@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.
Hi, how to use bearer token? my application has token to get the data. how work with that?
This token needed to establish connection to your API. You should put this token in the header of API request with name "Authorization"
Hi Artem, maybe its time to publish something '@New'
I regularly publish something new on Udemy. As well as keeping it up to date.
@@artembondar6577 a added this comment year ago 🙂
Cheers
hero
How to reuse fixture json file? :D
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
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