Skip to content

Commit

Permalink
Add "overwrite" option to cy.screenshot() (#4122)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmunechika authored Oct 6, 2021
1 parent 8c0915a commit 02029f7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions content/api/commands/screenshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ Pass in an options object to change the default behavior of `.screenshot()`.
| `disableTimersAndAnimations` | `true` | When true, prevents JavaScript timers (`setTimeout`, `setInterval`, etc) and CSS animations from running while the screenshot is taken. |
| `padding` | `null` | Padding used to alter the dimensions of a screenshot of an element. It can either be a number, or an array of up to four numbers [using CSS shorthand notation](https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties). This property is only applied for element screenshots and is ignored for all other types. |
| `scale` | `false` | Whether to scale the app to fit into the browser viewport. This is always coerced to `true` when `capture` is `runner`. |
| `timeout` | [`responseTimeout`](/guides/references/configuration#Timeouts) | Time to wait for `.screenshot()` to resolve before [timing out](#Timeouts) |
| `timeout` | [`responseTimeout`](/guides/references/configuration#Timeouts) | Time to wait for `.screenshot()` to resolve before [timing out](#Timeouts)
| `overwrite` | `false` | Whether to overwrite duplicate screenshot files with the same file name when saving. |
| `onBeforeScreenshot` | `null` | A callback before a non-failure screenshot is taken. When capturing screenshots of an element, the argument is the element being captured. For other screenshots, the argument is the `document`. |
| `onAfterScreenshot` | `null` | A callback after a non-failure screenshot is taken. When capturing screenshots of an element, the first argument is the element being captured. For other screenshots, the first argument is the `document`. The second argument is properties concerning the screenshot, including the `path` it was saved to and the `dimensions` of the saved screenshot. |

Expand Down Expand Up @@ -173,7 +174,14 @@ Screenshot naming follows these rules:
- For a named screenshot, the name is used instead of the suites and test name:
`{screenshotsFolder}/{specPath}/{name}.png`
- For any duplicate screenshots (named or not), they will be appended with a
number: `{screenshotsFolder}/{specPath}/{testName} (1).png`
number: `{screenshotsFolder}/{specPath}/{testName} (1).png`.

<Alert type="info">

This behavior can be changed by passing the `{overwrite: true}` option to `cy.screenshot()` to explicitly overwrite duplicate screenshots.

</Alert>

- For a failure screenshot, the default naming scheme is used and the name is
appended with ` (failed)`:
`{screenshotsFolder}/{specPath}/{testName} (failed).png`
Expand Down

0 comments on commit 02029f7

Please sign in to comment.