I have two identical API requests but different payloads. For example
- Request URL: http://localhost:8000/getdata/
Request Method: POST
Request body: { dataCategory:"Hardware" }
- Request URL: http://localhost:8000/getdata/
Request Method: POST
Request body: { dataCategory:"Software" }
My current code -
cy.intercept({
method: 'POST',
url: '/getData',
}).as('apiCheck');
cy.get(desktopElements.SomeElement).click();
cy.wait('@apiCheck').then((interception) => {
assert.isNotNull(interception.request.body.dataCategory, 'Request');
})
I know for a fact that I cannot include dataCategory inside the intercept method. Is there a way to achieve this?
If you want the intercept to be specific to the value of
dataCategory, add a dynamic alias - ref documentation Aliasing individual requests