Episode #212

Fastlane

16 minutes
Published on March 10, 2016

This video is only available to subscribers. Get access to this video and 586 others.

In this episode we set up fastlane to automate a lot of the tedious tasks related to building and deploying iOS applications. We use it to create our bundle identifier, create certificates and provisioning profiles, build and test our app, take screenshots on multiple devices, and submit to TestFlight.

Episode Links

Installing Fastlane

I like to use bundler to manage ruby dependencies in my projects. This makes it easy for others to know what gems (and what versions) we're using in the project.

If you don't have bundler installed, type:

gem install bundler

Then create your Gemfile with:

bundle init

Then edit the Gemfile and add:

gem 'fastlane'

Save the file, then run:

bundle install

Once that's done, we can set up fastlane...

Setting up Fastlane

Run fastlane init to have fastlane create the initial files you'll need. In addition, it will prompt you for your Apple ID, your team, bundle identifier and a few other questions.

Take a look at your generated Fastfile for details on the lanes fastlane has available to you by default.

Creating Certs & Profiles

We'll create an additional lane to create and download our certificates and profiles. Open up the Fastfile and add this lane:

  desc "Download/create certificates and profiles"
  lane :provisioning do
    cert(development: true, output_path: "provisioning")
    sigh(development: true, output_path: "provisioning")

    cert(output_path: "provisioning")
    sigh(adhoc: true, output_path: "provisioning")
    sigh(output_path: "provisioning")
  end

Automating Taking Screenshots

To automatically take screenshots with the snapshot tool (or action), run bundle exec snapshot init to create the initial Snapfile and helper swift file. Drag this into your project and add it to your UI test target.

    func testExample() {
        snapshot("0-Launch")
        let label = app.staticTexts.elementMatchingType(.Any, identifier: "timeLabel")
        label.tap()

        let mainView = app.windows.childrenMatchingType(.Any).elementBoundByIndex(0)
        let coords = mainView.coordinateWithNormalizedOffset(CGVector(dx: 0.05, dy: 0.05))
        coords.tap()

        snapshot("1-24htime")
    }

This will automatically capture 2 snapshots for every device/locale that is configured.

This episode uses Fastlane 1.66.0.