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

API req & res in mochawesome (not entirely redundant) #169

Open
aubincc opened this issue Jul 6, 2022 · 0 comments
Open

API req & res in mochawesome (not entirely redundant) #169

aubincc opened this issue Jul 6, 2022 · 0 comments
Assignees

Comments

@aubincc
Copy link

aubincc commented Jul 6, 2022

Pretty similar to #165 I guess, but this is a request for advice.

I am using nasty functions in order to store and reuse data between requests.

In order to compensate with the fact that the logs give only the content of the it(), I added a conditional screenshot upon failure of the test. (see code and screenshot below and maybe this helps @kivysyar with his own problem)

I made it conditional because otherwise it requires more disk space and time to execute, but the downside is, I only have the content of the failing request, not that of the couple of previous requests.

I would love to replace the content of the it() with the actual request and the actual response, just like it shows in the html.

My question is: should I look into modifying my code, cy-api or the mochasome reporter instead?


// in the test file
afterEach(() => {
  cy.takeScreenshotIfAutomatedTests();
});
// my custom command
import addContext from "mochawesome/addContext";

Cypress.Commands.add("takeScreenshotIfAutomatedTests", (capture) => {
  let screenshot;
  if (Cypress.env("CI") && Cypress.state().ctx.currentTest.state === "failed") {
    cy.screenshot("screenshot", {
      capture: capture, // Captures "fullpage" if undefined
      overwrite: true,
      onAfterScreenshot($el, props) {
        screenshot = props.path;
      },
    }).then(() => {
      cy.once("test:after:run", (test) => {
        addContext({ test }, screenshot);
      });
    });
  }
});

image

@LeJeanbono LeJeanbono self-assigned this Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants