How to automate taking screenshots with fastlane for iOS
Learn how to setup fastlane's snapshot action.
24 Jul 2023 · 2 min read
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:
- 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.
Like to support my work?
Articles with related topics
Continuous integration and delivery for iOS
Learn CI/CD concepts and possible workflows for iOS applications.
29 May 2023 · 5 min read
Quick guide on fastlane for iOS development
Learn to automate steps like running tests, code signing, build uploading and more.
13 Feb 2023 · 8 min read
Authorizing App Store Connect API requests
Learn how to create and use a JSON Web Token when communicating with the App Store Connect API.
26 Dec 2022 · 4 min read
Developer guide on iOS code signing & provisioning
Understanding provisioning profiles & certificates.
12 Dec 2022 · 4 min read
Developer guide on the App Store Connect API
Learn how to automate App Store Connect.
28 Nov 2022 · 7 min read
Latest articles and tips
Introduction to Kotlin for Swift developers - protocols, extensions & generics
Learn how protocols, extensions and generics in Kotlin work from a Swift developer's point of view.
02 Dec 2023 · 8 min read
How to store images in SwiftData
Learn how to efficiently store larger amounts of data in SwiftData.
27 Nov 2023 · 1 min read
How to migrate to a new schema with SwiftData in iOS
Learn how to create a migration plan in SwiftData.
20 Nov 2023 · 4 min read
How to implemet a free trial period for StoreKit 2 subscriptions in iOS
Learn how to implement StoreKit 2 introductory offers.
13 Nov 2023 · 2 min read
How to migrate from Localizable.strings to String Catalogs
Learn how to migrate your iOS project to .xcstrings for localization.
06 Nov 2023 · 1 min read