Reputation: 41
I make a post request via cy.request. The post internally redirects to another site along with a fragment (for eg: http://xyz redirects to http://www.lll.com/#fragData=1). I would like to capture the value of fragData.
From documentation cy.request only yields a response.
Could you please help?
Upvotes: 0
Views: 55
Reputation: 41
I found a useful setting to resolve this - followRedirect can be set to false to capture the 302 and fragment data.
Documentation link: https://docs.cypress.io/api/commands/request.html#Options
Eg:
cy.request({
url: '/dashboard',
followRedirect: false // turn off following redirects
})
.then((resp) => {
// redirect status code is 302
expect(resp.status).to.eq(302)
expect(resp.redirectedToUrl).to.eq('http://localhost:8082/unauthorized')
})
Upvotes: 4