Capture screenshots of the WordPress admin
This is a collection of scripts for taking and comparing screenshots of WordPress admin pages. This is mostly a personal tool, where I create scripts to run through various pages while testing tickets.
cd grab-screenshots
npm install
npm run snap
The scripts use environment variables for configuration. Pass these in before the script command, ex:
WP_BASE_URL=http://localhost:8888 npm run snap
The following variables are used for index.js
/npm run snap
.
Env Variable | Default | Description |
---|---|---|
WP_USERNAME | admin | Username to log in with, should have access to all pages that are requested. |
WP_PASSWORD | password | Password for account. |
WP_BASE_URL | http://trunk.wordpress.test/ | The URL to the running WordPress instance. Note, this does not have to be a local install. |
IMAGE_PATH | screenshots | Where the screenshots will be saved. This directory needs to exist already. |
index.js
Run this with npm run snap
. It will loop over all core color schemes and take screenshots of an assortment of pages, sometimes with elements hovered or focused. Read through the script to see the steps it takes.
diff.js
Run this with npm run diff
. Assuming you have two folders of matching screenshots, this will run blink-diff
over each file-pair in the folders.
Env Variable | Default | Description |
---|---|---|
IMAGE_A_PATH | photos-a | First folder of screenshots. |
IMAGE_B_PATH | photos-b | Second folder of screenshots. |
DIFF_PATH | photos-diffs | Output folder for visual diffs. |
If you want to check the difference between two branches of WordPress, you could
trunk
and build.mkdir screenshots-trunk
IMAGE_PATH=screenshots-trunk node index.js
mkdir screenshots-branch
IMAGE_PATH=screenshots-branch node index.js
mkdir screenshots-diff
IMAGE_A_PATH=screenshots-trunk IMAGE_B_PATH=screenshots-branch DIFF_PATH=screenshots-diff npm run diff
screenshots-diff
with the differences highlighted.