Whenever something repetitive starts to happen, we create a tool that automates these tasks, such as committing/pushing/merging git after writing code, taking screenshots, running tests, etc.
Fastlane is an integration tool written in Ruby that includes tools for building, testing, uploading, screenshots, and more, and has been acquired by Google.
About the Fastlane
Fastlane includes tools for packaging, signing, testing, deployment, publishing, and so on. You can also write your own Plugin in Ruby.
These should be used initially on iOS:
- Scan – run tests.
- Gym – build the app.
- Deliver — Upload screenshots, metadata, app to App Store.
- Take away — automate taking screenshots
- Pilot — Upload a new binary to iTunes Connect for TestFlight beta testing.
- Sigh – Handles Provisioning profiles.
For more tools check out the official Actions list.
Repetitive work in continuous integration
When we’re done with some of our development, we publish it to Testflight for testing, and the process might look something like this:
- Execute Git pull on the release computer to get the latest code.
- Execute Pod Install to install/update dependencies.
- Change the Version/Build number in XCode.
- Code is archived and packaged using XCode.
- Select an IPA file to upload.
- Upload ipA files using Xcode or Application Loader.
- Wait for the upload process to complete, log into iTunes Connet and select the version you want to test (only the first setting).
- Commit code (because xcode has changed version/build number)
You have to do this every time you finish a piece of code, and there’s testing involved, so it takes a lot of time.
Install & initialize Fastlane
Fastlane can be installed using Ruby gems:
gem install fastlaneCopy the code
Initialize Fastlane in an Xcode project:
fastlane initCopy the code
The initialization process will ask you to fill in your iTunes Connect account information, and if it’s a new project, it will help you set up your App in iTunes Connect.
Once set up, you can see that the Xcode project will have an additional Faselane directory.
Appfile
App Identifier, Apple ID, Team ID… And so on.
Note that if you have more than one team on your account, you can set itc_team_id or itc_team_name directly here, because if you don’t set itc_team_id or itc_team_name, fastlane will ask the user which team to use when performing release-related tasks, so there is no way to automate it.
You can read more about setting Appfile here.
Deliverfile
Here you can set app Identifier and User name (Apple User ID) directly if you have multiple teams on your account.
It can also be added during specific tasks, such as pilot(team_name: “Don Chen”)
You can read more about Deliverfile’s Settings here.
Fastfile
Here is an example of the command to execute, packaged and uploaded to TestFlight:
desc "Submit a new Beta Build to Apple TestFlight"
desc "This will also make sure the profile is up to date"
lane :beta do
# match(type: "appstore") # more information: https://codesigning.guide
increment_build_number
gym(scheme: "Lab-Fastlane") # Build your app - more options available
pilot(team_name: "Tung Chen")
# sh "your_script.sh"
# You can also use other beta testing services here (run `fastlane actions`)
endCopy the code
Pilot specifies team_name because my account has multiple teams.
Executing a task in Terminal:
fastlane ios betaCopy the code
Increment_build_number automatically increments the build number by 1, which needs to be set with Xcode.
The lane name for this task is beta, so if you visit Fastlane ios Beta in Terminal, you’ll start automating the task.
- Increment_build_number – Increases the build number by 1
- Gym (Scheme: “lab-Fastlane”) — Build project
- Pilot (team_name: “Tung Chen”) — Upload to TestFlight(iTunes Connect).
Note that:
Currently, iTunes Connect requires an App to fill in an “export compliance certificate”. If the code is not encrypted, it can be set to No.
In info.plist you can set:
Fastlane Metadata
We used the example of publishing an app to TestFlight, and we’ll talk about release.
- Copyright. TXT – Enter copyright information, such as Copyright (c) 2017 Don
- Primary_category.txt – Fill in the primary category, such as Games
- Primary_first_sub_category. TXT – Enter a category, such as Card
- Primary_second_sub_category. TXT – Enter the Second_sub category, for example, Casino
Publishing information can also be created for different app markets:
en-US, en-CA, fi, ru, zh-Hans, nl-NL, zh-Hant, en-AU, id, de-DE, sv.......Copy the code
You can see more about the Settings for Deliver here.
Screenshots
Here we will use the snapshot tool
Add the iOS UI Test Bundle File -> New Target -> iOS UI Test Bundle.
Then initialize the snapshot in our project:
fastlane snapshot initCopy the code
At this time the fastlane folde there will be many a SnapshotHelperXcode8. Swift, drag the files directly into the created UITests.
Sanpfile
In addition to the SnapshotHelper mentioned earlier, you will see a snapFile configuration file.
devices([
"iPhone 5s",
"iPhone 7"
])
languages([
"en-US",
"zh-Hant"
])
# Where should the resulting screenshots be stored?
output_directory "./screenshots"
clear_previous_screenshots trueCopy the code
- Devices: You can specify the type of device you want to enable. Be case sensitive. For example, if you want to enable iPhone 7 Plus, you can select iPhone 7 Plus.
- Languages: You can specify the language of the device. In this way, multiple languages can be used in screenshots
- Output_directory: indicates the directory for saving snapshots.
- Clear_previous_screenshots: Do not clear the original file each time you take a screenshot.
See more about Sanpshots Settings here.
UITests
We performed our screenshot tasks with UITests:
Let App = XCUIApplication() setupSnapshot(App) app.launch() snapshot("home-01") // Buttons ["home button"].tap() snapshot("one-01") // 3 - Buttons ["one button"].tap() snapshot("two-01") }Copy the code
- Where snapshot(” image name “) – this is the method of taking a screenshot.
The process of execution:
Download the files
We’ll see testing performing tasks, switching languages, etc., and finally we’ll see our images in ScreenShots: