Argos CI: Compare Only Selected Pages
In this article
Argos CI is a visual regression testing tool that compares screenshots of your web pages to catch unintended UI changes. By default, it compares every page you configure in your test suite. However, comparing a large site can be slow and noisy, especially when only a few pages changed. This guide shows you how to configure Argos CI to compare only the pages you select, saving time and focusing your review on the areas that matter.
What You'll Need
- An Argos CI account and a project set up (you can get one at argos-ci.com).
- An Argos CI token (ARGOS_TOKEN) stored as an environment variable in your CI system.
- Your project already integrated with Argos CI (e.g., using the Argos Playwright SDK or the CLI).
- Access to your test files (e.g., Playwright, Cypress, or a custom script) where you define which pages to capture.
Step-by-Step
- Understand how Argos selects pages. Argos compares screenshots that you send to it via its SDK or CLI. By default, it compares all screenshots in a build. To compare only selected pages, you need to control which screenshots are sent in the first place. There are two main approaches: filtering at the test level (only capture screenshots for the pages you want) or filtering at the Argos CLI level (using the
--filesor--onlyoption). The latter is simpler if you already have a full suite of screenshots. - Install the Argos CLI (if not already). If you are using the CLI directly (e.g., with Puppeteer or a custom script), ensure you have the
@argos-ci/clipackage installed. Runnpm install -D @argos-ci/cliin your project root. - Identify the pages you want to compare. Decide which pages are relevant for this build. For example, if you changed the header component, you might want to compare the homepage, product listing, and checkout pages. Write down the file paths or URLs of those pages.
- Option A: Filter screenshots using the CLI's
--filesoption. When you run the Argos upload command, use the--filesflag to specify a glob pattern that matches only the screenshot files you want to include. For example, if your screenshots are stored in a directory likescreenshots/and you only want to compare the homepage and product pages, run:npx argos upload screenshots --files "screenshots/{home,product-list}.png". This tells Argos to ignore all other screenshots in that directory. - Option B: Filter at the test level (Playwright/Cypress). If you are using the Argos Playwright SDK, you can conditionally take screenshots. In your test spec, wrap the
argosScreenshot()call in a condition that checks an environment variable or a flag. For example, in a Playwright test:
Then settest('homepage', async ({ page }) => { await page.goto('/'); if (process.env.COMPARE_PAGES === 'home') { await argosScreenshot(page, 'home'); } });COMPARE_PAGES=homein your CI environment for that build. This way, only the 'home' screenshot is sent to Argos. - Option C: Use a separate build for selected pages. If you have a large suite, you can create a separate Argos build that only includes the selected pages. For example, in your CI pipeline, you could have a job that runs only the tests for those pages and uploads them with a different build name (using
--build-name). This keeps the main build unchanged but gives you a focused comparison for the selected pages. - Verify the configuration. After making the change, run your CI pipeline and check the Argos dashboard. You should see only the selected pages in the build. If you see more or fewer, adjust the glob pattern or condition accordingly.
- Automate the selection. To make this dynamic, you can determine which pages to compare based on the changed files in the commit. For example, in a GitHub Action, you can use
dorny/paths-filterto detect which directories changed and set an environment variable that your test script reads. This way, the selection is automatic and always relevant.
Common Mistakes
- Using an incorrect glob pattern. The
--filesoption is case-sensitive and follows the glob syntax. A pattern likescreenshots/*.pngwill match all PNGs in the directory, but not in subdirectories. Test your pattern locally with a tool likeglobto ensure it matches exactly what you want. - Forgetting to update the upload command. If you are using the CLI, make sure you actually pass the
--filesoption. It is easy to forget and upload everything. - Hardcoding page names in test code. If you hardcode a list of pages in your test, you will have to update the code every time you want to change the selection. Prefer using environment variables or a configuration file.
- Not considering the base branch. Argos compares the current build against the base branch (e.g., main). If you only upload selected pages, the comparison will only show differences for those pages. That is fine, but be aware that changes on other pages will not be detected in this build.
- Mixing up file paths. When using the CLI, the
--filespattern is relative to the current working directory. If you run the command from a different directory, the pattern may not match anything.
Tips
- Use a naming convention for screenshots. Name your screenshot files based on the page or feature, e.g.,
home.png,product-detail.png. This makes it easier to write glob patterns. - Leverage environment variables. Instead of hardcoding a list, use an environment variable like
ARGOS_SELECTED_PAGESand parse it in your script. This allows you to change the selection without editing code. - Combine with CI triggers. If you only want to compare selected pages on pull requests that touch specific files, use CI conditional steps (e.g.,
ifin GitHub Actions) to skip the upload entirely when not needed. - Keep a full build for nightly runs. While you can compare only selected pages for PRs, it is a good practice to run a full comparison nightly to catch any unexpected changes across the whole site.
- Use the Argos API for fine-grained control. If you need more control, you can use the Argos API directly to create builds and upload screenshots programmatically. This allows you to filter exactly which screenshots to send.
Troubleshooting
- No screenshots appear in the build. If you see an empty build, check that your glob pattern matches at least one file. Run the command locally to see if it finds files. Also, make sure the screenshots are generated before the upload step.
- Too many screenshots are uploaded. If you are still seeing all screenshots, verify that you are passing the
--filesoption correctly. Check the command output for the list of files being uploaded. - The build fails with "No screenshots found". This error occurs when the glob pattern matches zero files. Double-check the path and the pattern. For example, if your screenshots are in a subdirectory, use
screenshots/**/*.png. - Environment variable not being read. If you are using a conditional in your test, ensure the environment variable is set in the CI environment. Print it in the test to verify. Also, make sure the variable name is spelled correctly.
- Argos compares the wrong pages. If you are using the CLI, remember that Argos compares the screenshots you upload, not the URLs. If you upload a screenshot of a page that has changed, it will be compared. Ensure that the screenshots you upload are indeed the ones you want to compare.
Frequently Asked Questions
Can I compare selected pages without changing my test code?
Yes, using the CLI's --files option is the simplest way. You just need to specify a glob pattern that matches the screenshot files you want to include. No code changes are required.
Does the --files option work with the Playwright SDK?
No, the --files option is for the CLI. If you use the Playwright SDK, you need to control which screenshots are taken in your test code, for example by using an environment variable.
Can I compare selected pages in a pull request only?
Yes, you can set up your CI to only run the selected pages on pull requests, and run the full suite on merges to main. Use conditional steps in your CI configuration.
What happens to the screenshots I don't upload?
They are simply not included in that build. Argos will not compare them. You can still upload them in a separate build if needed.
How do I know which pages changed in a commit?
You can use tools like dorny/paths-filter in GitHub Actions to detect changed files and set an environment variable accordingly. Then use that variable to decide which screenshots to upload.
Is it possible to compare selected pages across different branches?
Yes, Argos compares the current build against the base branch. As long as you upload the selected pages for both branches, the comparison will work. You can also use the --branch option to specify a different base branch.