No examples on how to validate XHR response (body, content-type and other)
See original GitHub issueLike in a title. I have found only this: https://github.com/cypress-io/cypress/issues/937
But there is only a short info:
cy.route('GET', '/login').as('getLogin')
cy.get('#contactID').type('email@gmail.com')
cy.contains('Login').click()
cy.wait('@getLogin').then(function(xhr){
// we can now access the low level xhr
// that contains the request body,
// response body, status, etc
})
How to access low level xhr? I would love to see some examples how to validate response body; for example: my response is:
[{
"Key": 16176,
"LineName": "Line A",
"displayFullName": "A-0300/0350 801"
},
{
"Key": 14567,
"LineName": "Line B",
"displayFullName": "C-876867"
}
]
I know that one element name should be A-0300/0350 801, now I want to verify that and also I need to retrieve it’s Key.
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
XMLHttpRequest.responseType - Web APIs | MDN
The XMLHttpRequest property responseType is an enumerated string value specifying the type of data contained in the response.
Read more >How to get the response of XMLHttpRequest? - Stack Overflow
Here's an example (not compatible with IE6/7). var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState == XMLHttpRequest.
Read more >Asserting on payloads · GitBook - GitHub Pages
Since we have a list of all the things we need to assert about, writing all the assertions is easy: request payload assertions....
Read more >Asserting Network Calls from Cypress Tests
The Cypress Test Runner can. ... We can see the outgoing XHR request and the server's response by looking at the DevTools Network...
Read more >XMLHttpRequest - The Modern JavaScript Tutorial
Some request methods like GET do not have a body. ... searchParams.set('q', 'test me! ... For example, let's get the response as JSON:....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After accessing the array, it’s mostly a matter of doing some functional programming to assert on what you want. Some examples -
Hopefully this helps you get started!
you can find examples here https://www.cypress.io/blog/2017/11/28/testing-vue-web-application-with-vuex-data-store-and-rest-backend/#api-testing which is linked from https://on.cypress.io/network-requests page. The Network Requests page could use a couple of examples right under https://on.cypress.io/network-requests#Assertions section