Cypress has the in-build capacity to take screenshots,
whether you are running in interactive mode using
cypress run and even in
CI as a part of the pipeline.
It can also capture screenshots automatically on the failure of
a test case when running via
to take a manual screenshot,
we can use the
Before version 8.6.0, the captured screenshots appends a number at the end of each screenshot taken within the same test.
After running the above test,
we can notice that there are two files
with the name
screenshot (1).png in the screenshots folder.
We can confirm the same with the images of the passing test and the directory.
Cypress 8.6.0 introduced the overwrite option to the cy.screenshot command.
overwrite is set to
the new screenshot will overwrite an existing screenshot with the same file name.
Notice how we have passed the
overwrite: true to the second screenshot command
now it will overwrite the existing screenshot and not append a number with a new file.
We can confirm it with the following images of the test and the directory.