メインコンテンツまでスキップ

スクリーンショット撮影

UIテストを使用してiOS/iPadOSシミュレーターからApp Storeのスクリーンショットを直接キャプチャします。fastlane snapshotの代替です。

クイックスタート

ascelerate screenshot init                  # Create config and helper in ascelerate/
ascelerate screenshot # Capture screenshots

コマンド

実行

ascelerate screenshot                       # Capture screenshots
ascelerate screenshot run # Same as above

常にカレントディレクトリの ascelerate/screenshot.yml を使用します。

初期化

ascelerate screenshot init

ascelerate/ ディレクトリに ascelerate/screenshot.ymlascelerate/ScreenshotHelper.swift の両方を作成します。書き込み前に確認を求めます。既存のファイルは上書きしません。

ヘルパー作成

ascelerate screenshot create-helper         # Generates ScreenshotHelper.swift
ascelerate screenshot create-helper -o CustomHelper.swift

設定(ascelerate/screenshot.yml

workspace: MyApp.xcworkspace
# project: MyApp.xcodeproj # Use project instead of workspace
scheme: AppUITests
devices:
- simulator: iPhone 16 Pro Max
- simulator: iPad Pro 13-inch (M4)
languages:
- en-US
- de-DE
outputDirectory: ./screenshots
clearPreviousScreenshots: true
eraseSimulator: false
localizeSimulator: true
overrideStatusBar: true
darkMode: false
disableAnimations: true
waitAfterBoot: 0
# statusBarArguments: "--time '9:41' --dataNetwork wifi"
# testWithoutBuilding: true # Skip build, use existing xctestrun
# cleanBuild: false
# headless: false # Don't open Simulator.app
# helperPath: AppUITests/ScreenshotHelper.swift
# launchArguments:
# - -ui_testing
# configuration: Debug # Build configuration
# testplan: MyTestPlan # Xcode test plan name
# numberOfRetries: 0 # Retry failed tests
# stopAfterFirstError: false # Stop all devices on first failure
# reinstallApp: false # Delete and reinstall app before tests
# xcargs: SWIFT_ACTIVE_COMPILATION_CONDITIONS=SCREENSHOTS

UIテストでの使用方法

ScreenshotHelper.swift をUITestターゲットに追加します:

override func setUp() {
setupScreenshots(app)
app.launch()
}

func testScreenshots() {
screenshot("01-home")
app.buttons["Settings"].tap()
screenshot("02-settings")
}

アプリ側でスクリーンショットモードを検出できます:

if ProcessInfo.processInfo.arguments.contains("-ASC_SCREENSHOT") {
// Show demo data, hide debug UI, etc.
}

ヘルパーは disableAnimationsIfNeeded() 関数も提供しており、設定で disableAnimations が有効な場合にアニメーションを無効化できます:

override func setUp() {
setupScreenshots(app)
disableAnimationsIfNeeded()
app.launch()
}

動作の仕組み

  1. build-for-testing で一度ビルド(testWithoutBuilding: true の場合はスキップ)
  2. 各言語ごとに:すべてのシミュレーターを起動、ローカライズ、ステータスバーをオーバーライド
  3. 全デバイスで並行してテストを実行
  4. デバイスごとのキャッシュから出力ディレクトリにスクリーンショットを収集
  5. エラーはスキップして続行 — エラーログは出力に保存

出力

screenshots/
├── en-US/
│ ├── iPhone 16 Pro Max-01-home.png
│ ├── iPhone 16 Pro Max-02-settings.png
│ └── iPad Pro 13-inch (M4)-01-home.png
└── de-DE/
└── ...

オプション

オプション説明
clearPreviousScreenshots収集前に言語フォルダをクリア(すべてのデバイスが成功した場合のみ)
eraseSimulator各言語の前にシミュレーターをリセット
localizeSimulator言語ごとにシミュレーターの言語/ロケールを設定
overrideStatusBarステータスバーをオーバーライド(9:41、フルバー、Wi-Fi)
statusBarArgumentsxcrun simctl status_bar のカスタム引数
darkModeシミュレーターでダークモードを有効化
disableAnimationsテスト中のアニメーションを無効化
waitAfterBootシミュレーター起動後の待機秒数(デフォルト: 0)
testWithoutBuildingビルドをスキップし、既存のxctestrunファイルを使用
cleanBuildビルド前に clean を実行
headlessSimulator.appを開かない
helperPathバージョンチェック用のScreenshotHelper.swiftへのパス
launchArgumentsアプリに渡す追加の起動引数
configurationビルド構成(例: Debug、Release)
testplanXcodeテストプラン名
numberOfRetries失敗したテストの再試行回数
stopAfterFirstError最初のエラー後にすべてのデバイスを停止
reinstallAppテスト前にアプリを削除して再インストール
xcargsxcodebuild に渡す追加の引数