azure-pipelinescypress

Azure pipeline fails to store cypress screenshots and videos - ##[error]Path does not exist: D:\a\1\s\cypress\screenshots


Hi I am trying to run cypress tests on azure pipelines and tests run fine but I am having trouble with screen shots and videos.

I get the error ---- ##[error]Path does not exist: D:\a\1\s\cypress\screenshots.

I am not sure if I have missed a step or yml tasks have mistakes. enter image description here

I tried using "CypressTests/cypress/screenshots" as well but does not work.

I have attached the screenshots file structure, .yml code and config.js

enter image description here

enter image description here

enter image description here


Solution

  • Figured out what the issue was. Screenshots folder was not found because it was never created during build. The reason for that was because in package.json the script was '"cypress:run": "cypress run".

    I replaced it with "cypress:run": "npx cypress run", and it works just fine.

    The replaced script let cypress create screenshots folder by default.

    Here is the snippet from package.json

    "scripts": {
    "cypress:open": "cypress open",
    "cypress:run": "npx cypress run", ---> This creates screenshot file by default
    "test": "echo \"Error: no test specified\" && exit 1"
    },
    

    Also cypress only creates screenshots folder if there is a failed run. So we can add this block to handle it

    after(() => {
            // Empty screenshot to ensure the directory is created
            cy.screenshot('final-screenshot');
          });