How to automate taking screenshots with fastlane for iOS
Learn how to setup fastlane's snapshot action.
24 Jul 2023 · 2 min read
As mentioned in this fastlane guide for iOS, fastlane provides a snapshot action to automatically generate screenshots for an iOS application.
Automatically taking screenshots of a mobile application can serve us developers in different ways, for example as part of publishing the app to the App Store, as part of a QA process or as part of UI testing to identify changes to previous versions.
Let's look at how we can use fastlane's snapshot action to do that.

The snapshot action uses the capabilities of UI tests to create the desired application state. If you never worked with UI tests before, check out this article on getting started with UI tests to learn more.
To setup snapshot, the following steps are required:
- Creating a new UI test target
- Running fastlane snapshot init in the project folder which will create a Snapfile and ./SnapshotHelper.swift
- Open the created Snapfile file to configure languages, devices and more, for example:
devices(["iPhone 14"])output_directory("./screenshots")clear_previous_screenshots(true)override_status_bar(true)
- Add the created ./SnapshotHelper.swift file to the UI Test target
- Add a new Xcode scheme for the created UI Test target, open its Build section and enable the Run and Shared checkbox.
- Add the following code in the setUp() method:
let app = XCUIApplication()setupSnapshot(app)app.launch()
- Add interactions to the UI test class that lead to desired screens and call snapshot("NameOfTheScreen") to take a screenshot where needed.
- Run fastlane snapshot in the terminal. It will create the screenshots inside the fastlane/screenshots directory.
To add device frames around created screenshots, we can use the fastlane frameit action. We also have the possibility to add a background and titles by setting up a Framefile.json.

Newsletter
Like to support my work?
Say hi
Related tags
Articles with related topics
Latest articles and tips