A bash script for generating Ghost Inspector visual regression test JSON files from a list of URLs, organized by domain.
- bash
- curl
- jq
The script checks for curl and jq at startup and exits with installation instructions if missing.
./generate-tests.shThe script will guide you through:
- Template Selection - Use the default
templates/template.jsonor paste a custom template - URL Input - Paste URLs one per line, press Enter on empty line when done
- Validation - Invalid URLs and duplicates are automatically skipped with warnings
- Confirmation - Review files to be created (existing files show
[OVERWRITE]warning) - File Generation - Creates JSON test files in
build/<domain>/subdirectories - Notes Generation - Creates
_notes.txtper domain with run history and settings - API Import (optional) - Import tests directly to a Ghost Inspector suite
See example.txt for a complete example run showing:
- Valid and invalid URLs
- Duplicate URL handling
- Domain organization output
- _notes.txt generation
- API import flow
Files are organized by domain in the build/ directory:
build/
├── example.com/
│ ├── _notes.txt
│ ├── Home.json
│ ├── About.json
│ └── Products_Widgets.json
└── other-site.com/
├── _notes.txt
└── Contact.json
Each _notes.txt contains:
- Last run timestamp
- Template used
- Test files table (filename, test name, URL)
- All template settings (screenshot compare, thresholds, browser, viewport, etc.)
- HTTP headers (if configured)
- Test steps with commands
This helps track when tests were generated and what each file is for.
Ghost Inspector Test Generator
===============================
Template options:
1) Use template.json (default)
2) Paste custom template
Select option [1]: 1
Using template.json
Paste your URLs (one per line).
Press Enter on an empty line when done:
https://example.com/
https://example.com/
https://invalid
https://example.com/about/
https://other.com/contact
Warning: Skipped 1 invalid URL(s):
Line 3: https://invalid
Warning: Skipped 1 duplicate URL(s):
https://example.com/
The following test files will be created:
-----------------------------------------
build/example.com/Home.json <-- https://example.com/
build/example.com/About.json <-- https://example.com/about/ [OVERWRITE]
build/other.com/Contact.json <-- https://other.com/contact
Warning: 1 file(s) will be overwritten.
Total: 3 test(s)
Proceed with file creation? (y/n): y
Creating test files...
Created: build/example.com/Home.json
Created: build/example.com/About.json
Created: build/other.com/Contact.json
Done! Created 3 test file(s).
Generating notes...
Created: build/example.com/_notes.txt
Created: build/other.com/_notes.txt
| URL | Filename | Test Name |
|---|---|---|
/ |
Home.json |
Home |
/about/ |
About.json |
About |
/funds/etfs/ |
Funds_Etfs.json |
Funds / Etfs |
/closed-end-funds/ |
Closed-End-Funds.json |
Closed End Funds |
- Filenames: path segments joined with
_, capitalized, hyphens preserved - Test names: path segments joined with
/, hyphens replaced with spaces
The script includes comprehensive input validation:
| Check | Behavior |
|---|---|
| Invalid URL format | Skips URLs not starting with http:// or https:// |
| Duplicate URLs | Skips exact duplicate URLs |
| Duplicate filenames | Skips URLs that produce the same output filename |
| Whitespace in URLs | Automatically trims leading/trailing spaces |
| Invalid JSON template | Exits if custom template is not valid JSON |
| Missing placeholders | Exits if template lacks TEST_NAME or START_URL |
| File overwrites | Displays [OVERWRITE] warning for existing files |
Invalid URLs and duplicates are reported but don't stop the script—valid URLs continue processing.
The template uses two required placeholders:
TEST_NAME- Replaced with human-readable test name derived from URL pathSTART_URL- Replaced with the full URL
Example: https://example.com/products/widgets/
TEST_NAMEbecomesProducts / WidgetsSTART_URLbecomeshttps://example.com/products/widgets/
To export existing test configurations as JSON for use with this script:
- Open Ghost Inspector test
- Click More menu (top right)
- Select Export test
- Download JSON file
- Use as custom template (option 2 in script) or modify for bulk generation
See assets/screenshot-export-test.png for visual walkthrough.
When importing tests to Ghost Inspector, the script prompts for your API key:
Enter API Key:
(input is hidden - type your API key and press Enter)
Key features:
- API key input is hidden (characters don't appear on screen)
- Key is never stored in script, config files, or shell history
- Key exists only in memory during the session
- Key is securely transmitted to Ghost Inspector API
- Key is safely discarded after import completes
Security practices:
- ✓ Use interactive prompts (don't hardcode keys)
- ✓ Never commit API keys to version control
- ✗ Never store keys in plaintext config files
- ✗ Never pass keys as command arguments
For detailed security practices and explanations, see example.txt (section: "Security Practices for API Keys").
MIT