Skip to content

Instantly share code, notes, and snippets.

@mark-alfonso
Last active January 16, 2020 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mark-alfonso/28f376ccc9576d8a4babd9186dfc7cb7 to your computer and use it in GitHub Desktop.
Save mark-alfonso/28f376ccc9576d8a4babd9186dfc7cb7 to your computer and use it in GitHub Desktop.
Automated screenshots generation with Fastlane and Xamarin

get lastest xcode commandline tools

xcode-select --install

install fastlane using homebrew

brew install fastlane

get all existing iOS simulators, list IDs

xcrun instruments -s devices

deploy simulators you want to take screenshot from using IDs listed

xcrun simctl boot <SIMULATOR-ID> xcrun simctl install <SIMULATOR-ID> <path\to\App> xcrun simctl shutdown <SIMULATOR-ID>

initialize fastlane snapshot

fastlane snapshot init

modify Snapfile to select which devices you want to use, in my case only iPhone 11, my laptop is a pretty old MBP 2012, can't support multiple simulators :(

 devices([
   "iPhone 11",
#   "iPhone 8 Plus",
#   "iPhone SE",
#   "iPhone X",
#   "iPad Pro (12.9-inch)",
#   "iPad Pro (9.7-inch)",
#   "Apple TV 1080p"
 ])

target SnapshotHelper.swift to FastlaneSnapshotXamarinTestUITests (my folder name for XCode UI test)

no terminal command needed, just select the SnapshotHelper.swift then under "Add to targets" section, select FastlaneSnapshotXamarinTestUITests

Changes for the creation of XCUIApplication

Still in SnapshotHelper.swift file, change from:

let deviceWidth = app.windows.firstMatch.frame.width

to:

let deviceWidth = XCUIApplication(bundleIdentifier: "com.<PACKAGENAME>.<APPNAME>").windows.firstMatch.frame.width

from:

let networkLoadingIndicator = app.otherElements.deviceStatusBars.networkLoadingIndicators.element

to:

let networkLoadingIndicator = XCUIApplication(bundleIdentifier: "com.<PACKAGENAME>.<APPNAME>").otherElements.deviceStatusBars.networkLoadingIndicators.element

create test file

import XCTest

class FastlaneSnapshotXamarinTestUITests: XCTestCase {

    func testExample() {
        let app = XCUIApplication(bundleIdentifier: "com.bohdanhrybach.FastlaneSnapshotXamarin")
        setupSnapshot(app)
        app.activate()
        
        let chipCountTextField = app.textFields["reverseText"]
        chipCountTextField.tap()
        chipCountTextField.typeText("Fastlane snapshot with Xamarin")
        
        snapshot("01UserEntry")
        
        app.buttons["reverseButton"].tap()
        
        snapshot("02Alert")
    }

}

run fastlane snapshot

fastlane snapshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment