When triggering an API request through a Cypress event, I need to extract the value of the applicationId parameter from the response body. This value is crucial for setting a variable or alias that will be used later in the code, specifically to provide it to another endpoint's path when making a cy.request() call.
Here is the XHR response body:
{
"applicationId": "abc",
"accessToken": "xyz"
}
I attempted to achieve this by using the following code:
cy.intercept("POST", "**/application").as("startApplication");
cy.wait('@startApplication').then((response) => {
cy.wrap(response.body.applicationId).as('applicationId')
})
However, I encountered an error in my IDE: Property 'body' does not exist on type 'Interception'.ts(2339), and during the execution of the Cypress test, it was stuck loading indefinitely.
Despite extensive googling and several hours of trying different methods, I have been unsuccessful thus far. As someone new to Cypress, TypeScript, and coding overall, I may be overlooking fundamental concepts.