cypress-har-generator
cypress-har-generator copied to clipboard
Unable to save HAR file when a `CypressError` is raised during the test
This spec DOES NOT generate a har
file when run.
describe("Smoke", () => {
beforeEach(() => {
cy.recordHar();
});
afterEach(() => {
cy.saveHar({ fileName: "smoke.har" });
});
it(["pre-deploy"], "loads the webpage without any issues", () => {
cy.visit("https://website-that-doesnt-exist.com");
});
});
I would expect the above spec to fail because it will get an ENOTFOUND
error, however I would still like a HAR file in this case.
If you tweak it to this then it does generate a HAR file.
describe("Smoke", () => {
beforeEach(() => {
cy.recordHar();
});
afterEach(() => {
cy.saveHar({ fileName: "smoke.har" });
});
it(["pre-deploy"], "loads the webpage without any issues", () => {
cy.visit("https://google.com");
});
});
If you make the version pointing to a valid website fail in a different way then it will still generate a HAR file. For example, this fails but will still give you a HAR.
describe("Smoke", () => {
beforeEach(() => {
cy.recordHar();
});
afterEach(() => {
cy.saveHar({ fileName: "smoke.har" });
});
it(["pre-deploy"], "loads the webpage without any issues", () => {
cy.visit("https://google.com");
cy.get("body").should("not.exist");
});
});
Ideally, I would like all three to still generate a HAR file to allow me to debug what is causing the CypressError.