Closed GrumpyMeow closed 3 years ago
I've found a good workaround. The selectPreset/selectScenario commands return information which exposes the apimockid cookie value. By setting the apimockid-cookie also on the domain you're making api-calls to, these api-calls will be in the same ngapimock-scope. This will make sure that the selected preset/scenario is actually used for returning the mocks. This will also allow for running multiple Cypress E2E tests in parallel.
cy.selectPreset('happy-flow').then((apiresult)=>{
const cookieheader = apiresult.requestHeaders.Cookie;
const cookies = cookieheader.split(';');
cookies.forEach((cookiestr: string) => {
const cookieparts = cookiestr.split('=');
if (cookieparts[0] == 'apimockid') {
cy.clearCookie('apimockid', { log: false });
cy.setCookie(cookieparts[0], cookieparts[1], { httpOnly: true, log: false });
Cypress.Cookies.preserveOnce(cookieparts[0]);
}
}
});
HI,
We're using ng-apimock for mocking for our Angular apps. In the CICD-pipeline we're doing a parallel Cypress E2E tests of our apps. We're experiencing flaky test-runs in this situation.
I think i've tracked it down to the fact that the webapi-calls that our app is making don't have the apimockid-cookie, while the apimockid-cookie is present on the ng-apimock-api-calls.
Can you maybe explain to me how the apimockid-cookie is expected to be added to the webapi-calls of our apps? I did some experimenting with adding a new method to a fork of your code to set the ngapimock-cookie in the context of the Cypress-test:
thanks in advance! groetjes, Sander