kikinteractive/snapshot_DELETED

Name: snapshot_DELETED

Owner: Kik Interactive

Description: Automate taking localized screenshots of your iOS app on every device

Created: 2016-02-02 06:50:01.0

Updated: 2017-05-21 17:31:18.0

Pushed: 2016-02-21 11:42:37.0

Homepage: https://fastlane.tools

Size: 7591

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README


fastlane

deliversnapshotframeitpemsighproducecertspaceshippilotboardinggymscanmatch


snapshot

Twitter: @FastlaneTools License Gem

Automate taking localized screenshots of your iOS app on every device

You have to manually create 20 (languages) x 6 (devices) x 5 (screenshots) = 600 screenshots.

It's hard to get everything right!

More information about creating perfect screenshots.

snapshot runs completely in the background - you can do something else, while your computer takes the screenshots for you.

Get in contact with the developer on Twitter: @FastlaneTools

Note: New snapshot with UI Tests in Xcode 7

Apple announced a new version of Xcode with support for UI Tests built in right into Xcode. This technology allows snapshot to be even better: Instead of dealing with UI Automation Javascript code, you are now be able to write the screenshot code in Swift or Objective C allowing you to use debugging features like breakpoints.

As a result, snapshot was completely rewritten from ground up without changing its public API.

Please check out the MigrationGuide to 1.0 :+1:

Why change to UI Tests?


FeaturesInstallationUI TestsQuick StartUsageTipsHow?Need help?


snapshot is part of fastlane: connect all deployment tools into one streamlined workflow.

Features

Like this tool? Be the first to know about updates and new fastlane tools

After snapshot successfully created new screenshots, it will generate a beautiful HTML file to get a quick overview of all screens:

assets/htmlPagePreviewFade.jpg

Why?

This tool automatically switches the language and device type and runs UI Tests for every combination.

Why should I automate this process?

Installation

Install the gem

sudo gem install snapshot

Make sure, you have the latest version of the Xcode command line tools installed:

xcode-select --install

UI Tests

Getting started

This project uses Apple's newly announced UI Tests. I will not go into detail on how to write scripts.

Here a few links to get started:

Note: Since there is no official way to trigger a screenshot from UI Tests, snapshot uses a workaround (described in How Does It Work?) to trigger a screenshot. If you feel like this should be done right, please duplicate radar 23062925.

Quick Start

Swift

app = XCUIApplication()
pSnapshot(app)
launch()

Objective C

Application *app = [[XCUIApplication alloc] init];
pshot setupSnapshot:app];
 launch];

assets/snapshot.gif

You can take a look at the example project to play around with it.

Usage

shot

Your screenshots will be stored in the ./screenshots/ folder by default (or ./fastlane/screenshots if you're using fastlane)

If any error occurs while running the snapshot script on a device, that device will not have any screenshots, and snapshot will continue with the next device or language. To stop the flow after the first error, run

shot --stop_after_first_error

Also by default, snapshot will open the HTML after all is done. This can be skipped with the following command

shot --stop_after_first_error --skip_open_summary

There are a lot of options available that define how to build your app, for example

shot --scheme "UITests" --configuration "Release"  --sdk "iphonesimulator"

Reinstall the app before running snapshot

shot --reinstall_app --app_identifier "tools.fastlane.app"

By default snapshot automatically retries running UI Tests if they fail. This is due to randomly failing UI Tests (e.g. #372). You can adapt this number using

shot --number_of_retries 3

Add photos and/or videos to the simulator before running snapshot

shot --add_photos MyTestApp/Assets/demo.jpg --add_videos MyTestApp/Assets/demo.mp4

For a list for all available options run

shot --help

After running snapshot you will get a nice summary:

Snapfile

All of the available options can also be stored in a configuration file called the Snapfile. Since most values will not change often for your project, it is recommended to store them there:

First make sure to have a Snapfile (you get it for free when running snapshot init)

The Snapfile can contain all the options that are also available on snapshot --help

me "UITests"

ces([
Phone 6",
Phone 6 Plus",
Phone 5",
Phone 4s"


uages([
n-US",
e-DE",
s-ES"


ch_arguments("-username Felix")

e directory in which the screenshots should be stored
ut_directory './screenshots'

r_previous_screenshots true

photos ["MyTestApp/Assets/demo.jpg"]
Completely reset all simulators

You can run this command in the terminal to delete and re-create all iOS simulators:

shot reset_simulators

Warning: This will delete all your simulators and replace by new ones! This is useful, if you run into weird problems when running snapshot.

You can use the environment variable SNAPSHOT_FORCE_DELETE to stop asking for confirmation before deleting.

Update snapshot helpers

Some updates require the helper files to be updated. snapshot will automatically warn you and tell you how to update.

Basically you can run

shot update

to update your SnapshotHelper.swift files. In case you modified your SnapshotHelper.swift and want to manually update the file, check out SnapshotHelper.swift.

Launch Arguments

You can provide additional arguments to your app on launch. These strings will be available in your code through NSProcessInfo.processInfo().arguments. Alternatively use user-default syntax (-key value) and they will be available as key-value pairs in NSUserDefaults.standardUserDefaults().

snapshot includes -FASTLANE_SNAPSHOT YES, which will set a temporary user default for the key FASTLANE_SNAPSHOT, you may use this to detect when the app is run by snapshot.

SUserDefaults.standardUserDefaults().boolForKey("FASTLANE_SNAPSHOT") {
// runtime check that we are in snapshot mode


name.text = NSUserDefaults.standardUserDefaults().stringForKey("username")
sername.text = "Felix"

Specify multiple argument strings and snapshot will generate screenshots for each combination of arguments, devices, and languages. This is useful for comparing the same screenshots with different feature flags, dynamic text sizes, and different data sets.

apfile for A/B Test Comparison
ch_arguments([
secretFeatureEnabled YES",
secretFeatureEnabled NO"

How does it work?

The easiest solution would be to just render the UIWindow into a file. That's not possible because UI Tests don't run on a main thread. So snapshot uses a different approach:

When you run unit tests in Xcode, the reporter generates a plist file, documenting all events that occured during the tests (More Information). Additionally, Xcode generates screenshots before, during and after each of these events. There is no way to manually trigger a screenshot event. The screenshots and the plist files are stored in the DerivedData directory, which snapshot stores in a temporary folder.

When the user calls snapshot(...) in the UI Tests (Swift or Objective C) the script actually does a rotation to .Unknown which doesn't have any effect on the actual app, but is enough to trigger a screenshot. It has no effect to the application and is not something you would do in your tests. The goal was to find some event that a user would never trigger, so that we know it's from snapshot.

snapshot then iterates through all test events and check where we did this weird rotation. Once snapshot has all events triggered by snapshot it collects a ordered list of all the file names of the actual screenshots of the application.

In the test output, the Swift snapshot function will print out something like this

snapshot: [some random text here]

snapshot finds all these entries using a regex. The number of snapshot outputs in the terminal and the number of snapshot events in the plist file should be the same. Knowing that, snapshot automatically matches these 2 lists to identify the name of each of these screenshots. They are then copied over to the output directory and separated by language and device.

2 thing have to be passed on from snapshot to the xcodebuild command line tool:

If you find a better way to do any of this, please submit an issue on GitHub or even a pull request :+1:

Also, feel free to duplicate radar 23062925.

Tips

fastlane Toolchain
Like this tool? Be the first to know about updates and new fastlane tools
Frame the screenshots

If you want to add frames around the screenshots and even put a title on top, check out frameit.

Available language codes
LANGUAGES = ["da", "de-DE", "el", "en-AU", "en-CA", "en-GB", "en-US", "es-ES", "es-MX", "fi", "fr-CA", "fr-FR", "id", "it", "ja", "ko", "ms", "nl", "no", "pt-BR", "pt-PT", "ru", "sv", "th", "tr", "vi", "zh-Hans", "zh-Hant"]
Use a clean status bar

You can use SimulatorStatusMagic to clean up the status bar.

Editing the Snapfile

Change syntax highlighting to Ruby.

Simulator doesn't launch the application

When the app dies directly after the application is launched there might be 2 problems

Determine language

To detect the currently used localization in your tests, use the following code:

can access the language using the `deviceLanguage` variable.

Need help?

Please submit an issue on GitHub and provide information about your setup

Code of Conduct

Help us keep snapshot open and inclusive. Please read and follow our Code of Conduct.

License

This project is licensed under the terms of the MIT license. See the LICENSE file.

This project and all fastlane tools are in no way affiliated with Apple Inc. This project is open source under the MIT license, which means you have full access to the source code and can modify it to fit your own needs. All fastlane tools run on your own computer or server, so your credentials or other sensitive information will never leave your own computer. You are responsible for how you use fastlane tools.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.