Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to save HAR file when a CypressError is raised during the test #105

Open
gavinhenderson opened this issue Nov 21, 2022 · 4 comments
Assignees
Labels
Type: enhancement New feature or request.

Comments

@gavinhenderson
Copy link

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.

@derevnjuk derevnjuk self-assigned this Jan 9, 2023
@derevnjuk derevnjuk added the Type: bug Something isn't working label Jan 10, 2023
@derevnjuk derevnjuk changed the title Doesn't save har file when a CypressError is raised during the test Unable to save HAR file when a CypressError is raised during the test Jan 10, 2023
@derevnjuk
Copy link
Member

@gavinhenderson unfortunately, there is no quick fix. Cypress uses cy.request handling cy.visit sending requests via some proxy, outside of the browser. Perhaps, it can be solved by #59 intercepting the requests made by cy.request (simular to #48).

@derevnjuk derevnjuk added Type: enhancement New feature or request. and removed Type: bug Something isn't working labels Jan 19, 2023
@gavinhenderson
Copy link
Author

Hey @derevnjuk thanks for the reply and explanation. I had assumed that cy.visit was doing requests via the browser but I can now see what you mean about it happening outside the browser. This, isn't really a problem for me anymore because I have solved the root of the problem for my site so feel free to close this issue

@derevnjuk
Copy link
Member

@gavinhenderson I'll keep the issue open to verify it while working on issue #59. Currently, converted to a feature request.

@bartonhammond
Copy link

Question: When I have an error, the ScreenShot is done and I can trap that event
Is there a way to generate the HAR from here?

const { defineConfig } = require('cypress')
module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      on('after:screenshot', (details) => {
        /* 
       is there a way to save the HAR file from here?
       I tried  cy.saveHar but get an error that cy is not defined
       */
      })
    },
  },
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: enhancement New feature or request.
Projects
None yet
Development

No branches or pull requests

3 participants