Replies: 3 comments 4 replies
-
You can use https://docs.cypress.io/api/commands/intercept It does this exact thing - you can intercept and see the request (and continue it, or prevent it, or whatever you like). |
Beta Was this translation helpful? Give feedback.
-
I tried this solution: I could print the response (header and body) in the "then" block after cy.request. In the example reported below I had to print the log duplicating the request into a string. cy.log(` method: 'POST', url: 'https://pre.windtre.it/ob/int/gw/api/v1/strong-auth/credentials', headers: {'X-Wind-Client': 'web','X-Brand': 'ONEBRAND','Customer-Id': ${codice_cliente}, body: {'rememberMe': true,'username': ${credenziali.username},'password': ${credenziali.password}}`)
cy.request({
method: 'POST',
url: 'https://pre.windtre.it/ob/int/gw/api/v1/strong-auth/credentials',
headers: {
'X-Wind-Client': 'web',
'X-Brand': 'ONEBRAND',
'Customer-Id': codice_cliente
},
body: {
"rememberMe": true,
"username": credenziali.username,
"password": credenziali.password
}
}).then((resp) => {
expect(resp.status).to.eq(200)
expect(resp.body.status).to.be.equal('OK')
cy.log("*** RESPONSE ***")
cy.log(JSON.stringify(resp.headers))
cy.log(JSON.stringify(resp.body))
challenge_token = resp.headers['x-w3-challenge-token']
cy.log('challenge token: '+ challenge_token)
cy.task('saveChallengeToken', challenge_token)
// imoosto variabile skip test a false perchè la login è passata
Cypress.env("SKIP_E2E_TESTS",false)
}) |
Beta Was this translation helpful? Give feedback.
-
If you are trying to intercept a request, you'll need to define the intercept and chain it with a cy.intercept('/fruit')
.as('getFruit')
.then(() => {
fetch('/fruit')
// format
.then((r) => r.json())
.then((body) => {
expect(body).to.have.property('fruit')
})
})
// now you can access the response and request
cy.wait('@getFruit').its('request.headers') |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is it possible to intercept / trace the HTTP/S data traffic produced by cypress test cases ? usually I use Charles/Fiddler as http proxy in order to snif http data traffic, but when I run test with Cypress I don't see any http traffic.
How can I do ?
I would like to use Cypress in order to run API testing and I need to see the HTTPS data traffic produced during the test, how can I do ?
Beta Was this translation helpful? Give feedback.
All reactions