cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.02k stars 3.18k forks source link

Trash assets failure with screenshots in nested folders #29404

Open MikeMcC399 opened 1 year ago

MikeMcC399 commented 1 year ago

If a test fails, then the option trashAssetsBeforeRuns with default true fails to delete previous screenshots on Windows 11 if there have been previous runs which produced screenshots in nested sub-folders of cypress/screenshots.

The error message is:

DevTools listening on ws://127.0.0.1:59399/devtools/browser/d422c0e5-e2d8-456e-9962-e48e167e8351
Warning: We failed to trash the existing run results.

This error will not affect or change the exit code.

Error: Command failed: C:\Users\mikem\AppData\Local\Cypress\Cache\12.13.0\Cypress\resources\app\node_modules\trash\lib\win-trash.exe C:\Users\mikem\github\cypress-io\cypress-realworld-app\cypress\screenshots\ui

    at ChildProcess.exithandler (node:child_process:407:12)
    at ChildProcess.emit (node:events:527:28)
    at maybeClose (node:internal/child_process:1092:16)
    at Process.onexit (node:internal/child_process:302:5)

The script dev is opening the screenshots, which prevents Cypress trash from working.

Steps to reproduce

Cypress: 12.13.0 13.0.0 Operating system: Windows 11 Node.js: 16.16.0 18.16.1

Create a new test spec cypress/tests/demo/show-fail.spec.ts with the following contents which will always fail when run:

it("show test failing", function () {
  throw new Error("deliberate hard failure");
});

Execute

yarn
yarn dev

then in a separate terminal window, execute

yarn cypress:run

The new test should fail and generate 3 screenshots and 1 video.

Kill the devprocess (if necessary sign out and back in again) and repeat

yarn dev

and again in a separate terminal window, execute

yarn cypress:run

Note the error message (see above).

Attempt to delete cypress/screenshots in Windows Explorer. Note message "Folder Access Denied / You'll need to provide administrator permission to delete this folder". Deletion is not possible.

Kill yarn dev process.

Attempt to delete cypress/screenshots in Windows Explorer. This is successful.

Suggestions

- When RWA is reworked, consider if this can be fixed.

MikeMcC399 commented 1 year ago
MikeMcC399 commented 1 year ago

Unfortunately it seems that this issue is unreliably reproducible 🙁 although it is still happening.

When it happens, screenshot copies build up, since they can't be deleted.

MikeMcC399 commented 7 months ago
jennifer-shehane commented 6 months ago

@MikeMcC399 It sounds like this issue should be moved to the main repo.