Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: set up included-non-root example screenshot #1273

Merged

Conversation

MikeMcC399
Copy link
Collaborator

@MikeMcC399 MikeMcC399 commented Jan 3, 2025

Issue

examples/included-as-non-root cannot capture screenshots when running with a non-root user in GitHub Actions.

In actions/workflows/example-tests.yml running the job example (included-as-non-root) in GitHub Actions, Cypress outputs the warning:

This folder is not writable: /test

Writing to this directory is required by Cypress in order to store screenshots and videos.

Enable write permissions to this directory to ensure screenshots and videos are stored.

If you don't require screenshots or videos to be stored you can safely ignore this warning.

See logs in https://github.com/cypress-io/cypress-docker-images/actions/runs/12585519287/job/35077469532

The workflow effectively runs the following:

#!/bin/bash
set -e # fail on error
#
# Run in examples/included-as-non-root directory
#
echo Test cypress/included running under node \(non-root\) user
docker run --rm -v .:/test -w /test -u node cypress/included

GitHub Runners under ubuntu-24.04 run commands with the Linux user:

uid=1001(runner) gid=118(docker) groups=118(docker),4(adm),100(users),999(systemd-journal)

The volume mount -v .:/test source is owned by the runner user and the Cypress node user has only r-x access, not write access to the directory /test.

Note that this is different from running Docker images as an explicit container in GitHub Actions (see Running jobs in a container where the Docker (default) user is root unless replaced through jobs.<job_id>.container.options).

Change

  1. In the Cypress configuration examples/included-as-non-root/cypress.config.js configure the volatile folders outside the Cypress project in the /tmp directory which is writable by all users.

    Folder Default Location New Location
    downloadsFolder cypress/downloads /tmp/cypress/downloads
    screenshotsFolder cypress/screenshots /tmp/cypress/screenshots
    videosFolder cypress/videos /tmp/cypress/videos
  2. Add cy.screenshot() to examples/included-as-non-root/cypress/e2e/spec.cy.js to test that a screenshot can be captured.

Verification

Local test Ubuntu

Ubuntu 24.04.1 LTS, Node.js 22.12.0 LTS, Docker Desktop 4.37.1

git clone https://github.com/cypress-io/cypress-docker-images
cd cypress-docker-images
cd examples/included-as-non-root
docker run --rm -v .:/test:ro -w /test -u node cypress/included

Local test Windows 11

Windows 11 24H2, Node.js 22.12.0 LTS, Docker Desktop 4.37.1 in a cmd terminal window

Commands and test as above for Ubuntu.

@cypress-app-bot
Copy link

@MikeMcC399 MikeMcC399 force-pushed the included-non-root-screenshots branch from 0dc31f7 to ca13655 Compare January 3, 2025 13:27
@MikeMcC399 MikeMcC399 force-pushed the included-non-root-screenshots branch from ca13655 to 259865d Compare January 3, 2025 13:28
@MikeMcC399

This comment was marked as resolved.

@MikeMcC399 MikeMcC399 marked this pull request as ready for review January 3, 2025 16:55
@MikeMcC399 MikeMcC399 self-assigned this Jan 4, 2025
@jennifer-shehane jennifer-shehane merged commit ae796ca into cypress-io:master Jan 6, 2025
36 checks passed
@MikeMcC399 MikeMcC399 deleted the included-non-root-screenshots branch January 6, 2025 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants