Screenshot automation

From gustavscirulis/snapgrid · View interactive version

Screenshot automation is an AI agent skill from the GitHub repository gustavscirulis/snapgrid. Generates an automated App Store screenshot pipeline with UI tests for screenshot capture, device framing, localized caption overlays, and multi-size batch export. Use when user wants automated screenshots, App Store screenshot generation, or a fastlane snapshot replacement.

How to use this skill

Skill file

Screenshot Automation Generator

Generate an automated App Store screenshot pipeline that captures screenshots via UI tests, adds localized marketing captions, applies device frames, and exports all required sizes for App Store Connect. Saves hours of manual screenshot creation every release.

When This Skill Activates

Use this skill when the user:

Pre-Generation Checks

1. Project Context Detection

2. Conflict Detection

Search for existing screenshot infrastructure:

Glob: **/*Screenshot*.swift, **/*Snapshot*.swift, **/Snapfile, **/Fastfile
Grep: "XCTAttachment" or "screenshot" or "snapshot" in UI test files

If fastlane snapshot already configured:

3. Localization Detection

Check for existing localization setup:

Glob: **/*.lproj/*.strings, **/*Localizable*, **/*.xcstrings

Determine which locales are already configured in the project.

Configuration Questions

Ask user via AskUserQuestion:

  1. Screenshot capture method?
  1. Target devices? (multi-select)
  1. Locales?
  1. Include device frames?
  1. Caption overlay style?

Generation Process

Step 1: Read Templates

Read templates.md for production Swift code and scripts.

Step 2: Create App-Side Screenshot Mode

Generate:

  1. ScreenshotModeController.swift -- Add to the app target (not tests). Detects --screenshot-mode launch argument and configures the app: suppresses onboarding, disables analytics/IAP, loads sample data, sizes windows (macOS). Also provides @Environment(\.isScreenshotMode) for views to hide promotional UI during capture.

Tell the user to:

Step 3: Create Configuration

Generate:

  1. ScreenshotPlan.swift -- Defines screens to capture, devices, locales, and output paths

Step 4: Create UI Test Files

Generate:

  1. ScreenshotUITests.swift -- XCUITest class that navigates and captures each screen
  2. ScreenshotTestHelper.swift -- Helper utilities for locale setup, data seeding, alert dismissal, plus tapUnhittable() extension for custom controls

Step 5: Create Post-Processing Files

Generate:

  1. ScreenshotProcessor.swift -- Loads captured images, routes through framing and captioning
  2. CaptionOverlay.swift -- Renders localized marketing text onto screenshot images

For macOS-only or lightweight needs, offer sips-screenshot-process.sh as an alternative to the Swift processor. Uses macOS's built-in sips command — zero dependencies.

Step 6: Create Export Script

Generate:

  1. ScreenshotExportScript.swift -- End-to-end pipeline script: build, test, process, organize

For macOS apps, also generate:

  1. macos-screenshot-env.sh -- Desktop preparation script (hides dock, desktop icons, simplifies clock) with trap-based cleanup

Step 7: Create Sample Content Generator

If the user needs realistic sample data for screenshots:

  1. SampleContentGenerator.swift -- Provides text content, chart data, placeholder images, and PDF generation (macOS). Category-specific sample titles for productivity, fitness, finance, and notes apps.

Step 8: Create Xcode Test Plan

Generate:

  1. ScreenshotTests.xctestplan -- Dedicated test plan that isolates screenshot tests from development tests. Prevents screenshot tests from running during Cmd+U.

Tell the user to:

Step 9: Determine File Locations

Check project structure:

Output Format

After generation, provide:

Files Created

App Target (source directory):
├── ScreenshotModeController.swift  # App-side screenshot mode detection & config
└── SampleContentGenerator.swift    # Realistic sample data for screenshots

UITests Target:
├── ScreenshotUITests.swift         # XCUITest capture class
└── ScreenshotTestHelper.swift      # Helper: locale, seeding, alerts, tapUnhittable()

ScreenshotAutomation/:
├── ScreenshotPlan.swift            # Configuration: screens, devices, locales
├── ScreenshotProcessor.swift       # Post-processing orchestrator
├── CaptionOverlay.swift            # Localized text overlay renderer
└── ScreenshotExportScript.swift    # Full pipeline script

Scripts/ (shell scripts):
├── sips-screenshot-process.sh      # Lightweight sips-based image processing
└── macos-screenshot-env.sh         # macOS desktop prep with trap cleanup

Project Root:
└── ScreenshotTests.xctestplan      # Dedicated test plan for screenshots

Integration with CI

Xcode Cloud:

# ci_scripts/ci_post_xcodebuild.sh
if [ "$CI_WORKFLOW" = "Screenshots" ]; then
    swift ScreenshotAutomation/ScreenshotExportScript.swift
fi

GitHub Actions:

- name: Generate Screenshots
  run: |
    xcodebuild test \
      -scheme "YourAppUITests" \
      -destination "platform=iOS Simulator,name=iPhone 16 Pro Max" \
      -testPlan ScreenshotPlan \
      -resultBundlePath screenshots.xcresult
    swift ScreenshotAutomation/ScreenshotExportScript.swift

fastlane (if selected):

lane :screenshots do
  capture_screenshots(scheme: "YourAppUITests")
  # Post-processing handled by ScreenshotProcessor
end

Testing and Running

Run screenshot tests from Xcode:

xcodebuild test \
  -project YourApp.xcodeproj \
  -scheme "YourAppUITests" \
  -destination "platform=iOS Simulator,name=iPhone 16 Pro Max" \
  -only-testing "YourAppUITests/ScreenshotUITests"

Run the full pipeline:

swift ScreenshotAutomation/ScreenshotExportScript.swift

Verify output directory:

screenshots/
├── en-US/
│   ├── iPhone_6.7/
│   │   ├── 01_HomeScreen.png
│   │   ├── 02_DetailView.png
│   │   └── 03_Settings.png
│   └── iPad_12.9/
│       ├── 01_HomeScreen.png
│       └── ...
├── de-DE/
│   └── ...
└── ja-JP/
    └── ...

Integration Steps

Add to existing UI test target:

// In your UITest scheme, add ScreenshotUITests.swift
// The test class auto-discovers screens from ScreenshotPlan

Localized captions file (Localizable.strings):

// en-US
"screenshot.home" = "Track your goals effortlessly";
"screenshot.detail" = "Deep insights at a glance";
"screenshot.settings" = "Customize everything";

// de-DE
"screenshot.home" = "Verfolgen Sie Ihre Ziele muhelos";
"screenshot.detail" = "Tiefe Einblicke auf einen Blick";
"screenshot.settings" = "Alles anpassen";

Testing

@Test
func screenshotPlanLoadsAllScreens() throws {
    let plan = ScreenshotPlan.default
    #expect(!plan.screens.isEmpty)
    #expect(plan.screens.allSatisfy { !$0.name.isEmpty })
}

@Test
func captionOverlayRendersText() throws {
    let overlay = CaptionOverlay(
        text: "Track your goals",
        style: .top,
        font: .systemFont(ofSize: 48, weight: .bold),
        textColor: .white
    )
    let sourceImage = PlatformImage.testScreenshot(size: CGSize(width: 1290, height: 2796))
    let result = try overlay.apply(to: sourceImage)
    #expect(result.size.height > sourceImage.size.height)
}

@Test
func processorOrganizesOutputByLocaleAndDevice() async throws {
    let processor = ScreenshotProcessor(outputDirectory: tempDir)
    let screenshot = CapturedScreenshot(
        name: "01_HomeScreen",
        image: .testScreenshot(),
        locale: "en-US",
        device: .iPhone6_7
    )
    try await processor.process([screenshot])

    let outputPath = tempDir
        .appendingPathComponent("en-US")
        .appendingPathComponent("iPhone_6.7")
        .appendingPathComponent("01_HomeScreen.png")
    #expect(FileManager.default.fileExists(atPath: outputPath.path))
}

Common Patterns

Capture Key Screens

Identify 6-10 screens that showcase the app's value proposition. Order them for maximum impact -- the first screenshot is the most important in App Store search results.

Add Captions

Marketing text should be short (3-6 words), benefit-focused, and localized. Use the app's brand fonts when possible.

Frame and Export

Device frames add professionalism. Export at exact App Store Connect required resolutions to avoid rejection.

Batch All Locales

Run the full pipeline once to generate screenshots for every locale simultaneously. Each locale uses its own localized strings and sample data.

Gotchas

Simulator vs Device Differences

Dark Mode Screenshots

Dynamic Type Screenshots

Screenshot Naming Convention for App Store Connect

Landscape Screenshots

macOS: Asymmetric Window Borders

macOS: Desktop Environment

macOS: Window Sizing for App Store

Custom Controls and tapUnhittable()

Isolating Screenshot Tests

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.