Adding Fastlane to an Xcode project Aug 15 2019
We can install Fastlane
as a Homebrew cask or as a gem. I'll go the gem route.
add a Gemfile on your project:
1
2
3
4
#Gemfile
source "https://rubygems.org"
gem "fastlane"
We are going to use bundler
. If you are familiar with Ruby development, you will find this standard procedure.
1
2
$ bundle update
$ bundle install
now we can run fastlane
because we want to use the version we currently installed, we will run it:
1
$ bundle exec fastlane init
Here it'll display a menu to create the initial configuration, We can skip this process and do the manual route. We'll try hard mode, so do it manually.
Table of Contents
Fastlane configuration files
Fastlane uses two files for most of the configuration, Appfile
and Fastfile
. Appfile
includes the application's information. Fastfile
defines all the lanes
that you can use on your fastlane setup. A lane
is a set of instructions that you want to put together and run as a whole.
The Fastfile
is written in a DSL (Domain Specific Language) for ruby, so you can use ruby inside the Fastfile
. If you've used RSpec for your tests, you'll be very comfortable with the DSL.
Setting up Screenshots
We are going to create a new Target. Go to Menu > New > Target ...
select iOS UI Testing Bundle
.
If we are going to record the UITest. If you get an error "Failed to set plugin placeholders", go to your project info, click your app Target, then select Build Phases
and there select the extension and make sure that copy only when installing
checkbox is ticked.
run in your Project's folder:
1
bundle exec fastlane snapshot init
And follow the instructions on the screen:
1
2
3
4
5
6
7
8
9
10
11
12
13
Open your Xcode project and make sure to do the following:
1) Add a new UI Test target to your project
2) Add the ./fastlane/SnapshotHelper.swift to your UI Test target
You can move the file anywhere you want
3) Call `setupSnapshot(app)` when launching your app
let app = XCUIApplication()
setupSnapshot(app)
app.launch()
4) Add `snapshot("0Launch")` to wherever you want to trigger screenshots
5) Add a new Xcode scheme for the newly created UITest target
6) Add a Check to enable the `Shared` box of the newly created scheme
This means add the snapshot(IDENTIFIER)
. We can now edit our Snapfile
, the configuration file for snapshots. Remember to set the correct scheme.
If we want to create a lane for it, edit your Fastfile
and add your lane.
1
2
3
4
5
desc "Take snapshots"
lane :screenshots do
capture_screenshots
#upload_to_app_store
end
You can now run the command:
1
$ bundle exec fastlane screenshots
Related topics/notes of interest
- How to fix the "Failed to set plugin placeholder"
- To view the documents for the user in the simulator. set a breakpoint and:
1
po NSHomeDirectory()