Skip to content

Commit

Permalink
docs(readme): add example to save har conditionally (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
azuruce authored Sep 24, 2020
1 parent 5a52c34 commit 2b35e96
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ It allows overriding the value, that is specified in the `cypress.json`
cy.saveHar({ outDir: './hars' });
```

Generate HAR file only for chrome, if it is not interactive run, and if test failed.
```js
beforeEach(() => {
const isInteractive = Cypress.config('isInteractive');
const isChrome = Cypress.browser.name === 'chrome';
if (!isInteractive && isChrome) {
cy.recordHar();
}
});
afterEach(() => {
const { state } = this.currentTest;
const isInteractive = Cypress.config('isInteractive');
const isChrome = Cypress.browser.name === 'chrome';
if (!isInteractive && isChrome && state !== 'passed') {
cy.saveHar();
}
});
```

If you want to change the path to the files, you can specify it by setting the `hars_folder` environment variable.

Expand Down

0 comments on commit 2b35e96

Please sign in to comment.