Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Testing Responsive Layouts with Argos CI Screenshots

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide walks you through setting up visual regression testing for responsive layouts using Argos CI. You'll learn how to capture screenshots at multiple viewport sizes, compare them against a baseline, and catch unintended UI changes before they reach production. By the end, you'll have a repeatable workflow that runs automatically in your CI pipeline.

What You'll Need

  • A Git repository with your frontend code (React, Vue, Angular, or plain HTML/CSS).
  • Node.js 18 or later installed locally.
  • An Argos CI account (free tier available) and an API token.
  • A CI provider (GitHub Actions, GitLab CI, CircleCI, etc.) or you can run locally.
  • Basic familiarity with Playwright or Puppeteer for browser automation.

Step-by-Step

  1. Set up Argos CLI in your project Install the Argos CLI as a dev dependency: npm install --save-dev @argos-ci/cli This gives you the argos command to upload screenshots.
  2. Create a Playwright config for multiple viewports If you don't have Playwright yet, install it: npm install --save-dev @playwright/test. Then create a config file (e.g., playwright.config.js) that defines projects for each viewport you want to test. For example:
    module.exports = {
      projects: [
        { name: 'mobile', use: { viewport: { width: 375, height: 667 } } },
        { name: 'tablet', use: { viewport: { width: 768, height: 1024 } } },
        { name: 'desktop', use: { viewport: { width: 1280, height: 800 } } },
      ],
    };
  3. Write a screenshot test Create a test file, e.g., visual.spec.js, that visits your key pages and takes screenshots. Use Playwright's page.screenshot() and save to a directory like screenshots/. Example:
    const { test } = require('@playwright/test');
    
    test('homepage responsive', async ({ page }) => {
      await page.goto('http://localhost:3000');
      await page.screenshot({ path: 'screenshots/home.png', fullPage: true });
    });
  4. Start your app before running tests In your CI script, start your development server or static file server in the background. For a React app, you might run npm run build && npx serve build or use Playwright's webServer option in the config.
  5. Run the tests to generate screenshots Execute npx playwright test to produce the screenshots. Verify they are saved in the expected folder.
  6. Upload screenshots to Argos After tests pass, run npx argos upload screenshots. This sends the images to Argos CI. You'll need to set the ARGOS_TOKEN environment variable (found in your Argos project settings).
  7. Integrate with CI Add a step in your CI workflow to run the tests and upload. For GitHub Actions, a basic workflow might look like: jobs: visual-test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 20 - run: npm ci - run: npm run build - run: npx playwright install --with-deps - run: npx playwright test - run: npx argos upload screenshots env:
  8. Review changes in Argos dashboard When you open a pull request, Argos will comment with a link to the visual diff. Review the changes, accept or reject them, and the status will update accordingly.

Common Mistakes

  • Forgetting to start the server – Screenshots will fail or capture an error page. Always ensure your app is running before tests.
  • Not installing browser binaries – Playwright needs browsers installed. Run npx playwright install in CI.
  • Ignoring dynamic content – Animations, carousels, or date pickers can cause flaky diffs. Freeze them or use fixed test data.
  • Uploading screenshots from local without a baseline – Argos compares against the last accepted build; if you upload from local, it might create a new baseline unintentionally.
  • Using fullPage for very long pages – This can create huge images that slow down uploads. Consider cropping to above-the-fold if needed.

Tips

  • Use --update-snapshots in Playwright to update local baselines when you intentionally change the UI.
  • Set a threshold for pixel differences in Argos (e.g., 0.1%) to ignore tiny anti-aliasing variations.
  • Group screenshots by feature or page to make reviews easier in the dashboard.
  • Run visual tests on a schedule (e.g., nightly) to catch regressions from dependency updates.
  • Use environment variables to switch between test and production data to avoid flaky content.

Troubleshooting

  • Upload fails with 401 Unauthorized – Check that ARGOS_TOKEN is set correctly and hasn't expired. Regenerate if needed.
  • Screenshots are blank or missing content – Your app may not have finished loading. Use page.waitForLoadState('networkidle') or wait for a specific element.
  • Diff shows changes everywhere – This often means the server wasn't running or the page failed to load. Check the screenshot in Argos to see if it's an error page.
  • Playwright can't find browsers in CI – Run npx playwright install --with-deps to install both browsers and system dependencies.
  • Argos comment not appearing on PR – Make sure your CI has permission to write comments. For GitHub Actions, ensure the token has pull-requests: write.

Frequently Asked Questions

Can I use Puppeteer instead of Playwright?

Yes, Argos CLI works with any tool that produces screenshots. You can use Puppeteer and save images to a folder, then upload with argos upload.

How does Argos handle dynamic content like dates?

Argos compares pixel by pixel, so dynamic content will cause diffs. You can mask such areas using Playwright's page.addStyleTag to hide them or use fixed test data.

Do I need a separate Argos project for each viewport?

No, you can upload all screenshots to one project. Argos will show them as separate builds or you can organize them by naming conventions.

Can I run Argos locally without CI?

Yes, you can run npx argos upload screenshots locally, but it will create a build that may affect your baseline. It's better to use a dedicated branch or local mode if available.

What happens when I accept a change in Argos?

That build becomes the new baseline for future comparisons. Subsequent uploads will be compared against it.

How do I ignore a specific screenshot from comparison?

You can exclude files from the upload using a glob pattern, e.g., npx argos upload screenshots --ignore "**/ignored.png".