API req & res in mochawesome (not entirely redundant)
- Dominant language
- TypeScript
- Stars
- 210
- Forks
- 26
- PR merge metrics
- No merged PRs in 30d
Description
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**?
---
``` js
// in the test file
afterEach(() => {
cy.takeScreenshotIfAutomatedTests();
});
```
``` js
// 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);
});
});
}
});
```

Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.