Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

ci(browser): publish Cypress preview screenshots

Gabe Kangasfce6934e14d8
diff --git a/.github/workflows/browser-testing.yml b/.github/workflows/browser-testing.yml
index 217d2401b2..55fcf387f0 100644
--- a/.github/workflows/browser-testing.yml
+++ b/.github/workflows/browser-testing.yml
@@ -247,14 +247,18 @@ jobs:
aws s3 cp "$f" "s3://$S3_BUCKET/$key" --endpoint-url "$S3_ENDPOINT" \
--acl public-read --content-type video/mp4 --no-progress >&2
poster_url=""
- # Capture near the end, after Cypress assertions have waited for the page to load.
- if [ -n "$FFMPEG" ] && "$FFMPEG" -v error -sseof -1 -i "$f" -frames:v 1 "${f%.mp4}.png"; then
- poster="${f%.mp4}.png"
- poster_url="$S3_ENDPOINT/$S3_BUCKET/${key%.mp4}.png"
- aws s3 cp "$poster" "s3://$S3_BUCKET/${key%.mp4}.png" --endpoint-url "$S3_ENDPOINT" \
+ # Cypress captures a preview from the last tested page before it tears
+ # down the browser. Do not extract a frame from a video tail: that can
+ # be blank, and specs without selected tests have no preview to publish.
+ dir="${f#videos/}"; dir="${dir%%/*}"
+ preview="screenshots/$dir/$(basename "${f%.mp4}")/preview.png"
+ if [ -f "$preview" ]; then
+ preview_key="$PREFIX/${preview#screenshots/}"
+ poster_url="$S3_ENDPOINT/$S3_BUCKET/$preview_key"
+ aws s3 cp "$preview" "s3://$S3_BUCKET/$preview_key" --endpoint-url "$S3_ENDPOINT" \
--acl public-read --content-type image/png --no-progress >&2
fi
- dir="${f#videos/}"; dir="${dir%%/*}"
+ # Group recordings under the same heading as their explicit preview.
if [ "$dir" != "$group" ]; then
group="$dir"
printf '\n**%s**\n\n' "$group"
diff --git a/test/automated/browser/cypress/support/e2e.js b/test/automated/browser/cypress/support/e2e.js
index bed182331c..0c751a75d0 100644
--- a/test/automated/browser/cypress/support/e2e.js
+++ b/test/automated/browser/cypress/support/e2e.js
@@ -1,16 +1,23 @@
import './commands';
+let ranTest = false;
+
+Cypress.on('test:after:run', () => {
+ ranTest = true;
+});
+
before(() => {
// Set server URL. Specs assume this instance is known as testing.biz.
cy.setConfig('serverurl', 'https://testing.biz');
});
after(() => {
- // When recording, pad the end of each spec: the CDP screencast delivers
- // frames with latency, and ending the spec immediately after its last
- // action drops the in-flight tail (recordings ended seconds before the
- // final tests' UI, e.g. the mobile name-change modal, ever appeared).
- if (Cypress.config('video')) {
+ // The screenshot is taken from the final tested state, before Cypress
+ // tears down the page. A frame chosen from the recording can be blank.
+ if (Cypress.config('video') && ranTest) {
+ cy.screenshot('preview');
+
+ // Pad the recording so its in-flight tail is retained for playback.
cy.wait(3000);
}
});
diff --git a/test/automated/browser/run.sh b/test/automated/browser/run.sh
index 41d0c6cb96..cb761b2610 100755
--- a/test/automated/browser/run.sh
+++ b/test/automated/browser/run.sh
@@ -80,9 +80,9 @@ FAILED_GROUPS=()
# Run one cypress group. Cloud recording (and the flags that require it) is
# CI-only: local runs stay fast and work offline. A failing group is recorded
# and the run continues, so a single run surfaces every broken group.
-# Extra config is merged into one --config flag because cypress honors only
-# the last --config it sees; videosFolder is per group so desktop and mobile
-# runs of the same specs don't overwrite each other's recordings.
+# Extra config is merged into one --config flag because Cypress honors only
+# the last --config it sees. Video and screenshot folders are per group so
+# desktop and mobile runs of the same specs don't overwrite each other's output.
# run_cypress <group> <tags-env> <spec-glob> [extra config key=value,...]
run_cypress() {
local group=$1 tags=$2 spec=$3 extra_config="${4:-}"
@@ -91,7 +91,7 @@ run_cypress() {
return 0
fi
- local config="videosFolder=cypress/videos/$group"
+ local config="videosFolder=cypress/videos/$group,screenshotsFolder=cypress/screenshots/$group"
if [ -n "$extra_config" ]; then
config="$config,$extra_config"
fi