motion-screenshots

Automate your App Store screenshots with rake screenshots. Powered by KSScreenshotManager.

Check out some sample output.

Installation

Add this line to your application's Gemfile:

gem 'motion-screenshots'

And then execute:

$ bundle

Or install it yourself as:

$ gem install motion-screenshots

And require in your Rakefile with:

require "motion-screenshots"

Usage

Configuration

By default, screenshots will be placed in a ./screenshots/#{timestamp} directory in your project. You can configure this a few different ways:

  • ENV['SCREENSHOTS_DIR'] - use this environment variable
  • app.screenshots_output_path= - set this value in your Rakefile
  • app.before_screenshots do - add this block in your Rakefile
  • app.after_screenshots do |output_path| - add this block in your Rakefile

Code

Create one or more subclasses of Motion::Screenshots::Base and add them to ./app/screenshots. This class uses a DSL you can use to setup what happens before and after various screenshots are taken.

class AppScreenshots < Motion::Screenshots::Base

  # Use `.screenshot` to take a synchronous shot
  screenshot "menu" do
    before do
      # scroll down for a nice action shot
      App.delegate.table_view_controller.scrollToRowAtIndexPath(
        NSIndexPath.indexPathForRow(2, inSection: 1),
        animated: false,
        scrollPosition: UITableViewScrollPositionMiddle
      )
    end
  end

  # Use `.async_screenshot` to take a screenshot
  # at some point in the future (i.e. a timer, network calls, etc)
  # Invoke `#ready!` to take the shot
  async_screenshot "profile" do
    ready_delay 3 # delays the screenshot to 3 seconds after ready! is called

    before do
      App.delegate.table_view_controller.selectRowAtIndexPath(
        NSIndexPath.indexPathForRow(0, inSection: 1),
        animated: false,
        scrollPosition: UITableViewScrollPositionNone
      )

      ready!
    end

    # clean-up
    after do
      App.window.rootViewController.popViewControllerAnimated(false)
    end
  end
end

Then, after your initial views have appeared, simply let motion-screenshots know when to start the process:

class MyFirstViewController

  def viewDidAppear(animated)
    super

    # May need to wrap in a Dispatch::Queue.main.async{} block
    AppScreenshots.start!
  end
end

Screenshots are executed in the order listed in your class - doing any cleanup or pre-screenshot preparation is left to you.

Running

Simple run rake screenshots and you're off! The task will uninstall and reinstall your CocoaPods, as to not include any of the private APIs bundled with KSScreenshotManager.

Contact

Clay Allsopp @clayallsopp