Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/playwright/install.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#!/bin/bash

npx playwright install --with-deps ${BROWSERS}
set -e

# Install Playwright browsers
# If _REMOTE_USER is set and not root, install as that user
# Otherwise install as root (test scenarios)
if [ -n "${_REMOTE_USER}" ] && [ "${_REMOTE_USER}" != "root" ] && id -u "${_REMOTE_USER}" > /dev/null 2>&1; then
su "${_REMOTE_USER}" -c "npx playwright install --with-deps ${BROWSERS}"
else
npx playwright install --with-deps ${BROWSERS}
fi
8 changes: 8 additions & 0 deletions test/playwright/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@
"browsers": "firefox chromium"
}
}
},
"test_user_install": {
"image": "ubuntu:focal",
"features": {
"playwright": {
"browsers": "chromium"
}
}
}
}
31 changes: 31 additions & 0 deletions test/playwright/test_user_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -e

source dev-container-features-test-lib

# Test that Playwright is installed
check "Playwright is available" npx playwright --version

# Check that browsers are installed in user's home directory (not root)
CURRENT_USER=$(whoami)
USER_HOME=$(eval echo ~${CURRENT_USER})

# Verify browser cache exists in the user's home directory
check "Browser cache in user home" test -d "${USER_HOME}/.cache/ms-playwright"

# Verify the cache directory is owned by the current user
check "Browser cache owned by user" bash -c "[ \"\$(stat -c '%U' ${USER_HOME}/.cache/ms-playwright)\" = \"${CURRENT_USER}\" ]"

# Verify browsers are not installed in root directory (if we're not root)
if [ "${CURRENT_USER}" != "root" ]; then
check "Browser cache not in root" bash -c "! test -d /root/.cache/ms-playwright || [ \"\$(ls -A /root/.cache/ms-playwright 2>/dev/null | wc -l)\" = \"0\" ]"
fi

# Test that browsers can be listed (validates installation)
check "Can list browsers" npx playwright install --list

# Verify the user can run playwright commands without permission issues
check "User can run playwright" bash -c 'npx playwright --help | grep -q "Usage"'

reportResults