module Calabash::Cucumber::IPad

Contains methods for interacting with the iPad.

Public Instance Methods

ensure_ipad_emulation_1x(opts={}) click to toggle source

Ensures that iPhone apps emulated on an iPad are displayed at ‘1X`.

@note If this is not an iPhone app emulated on an iPad, then calling

this method has no effect.

@note In order to use this method, you must allow Calabash to launch

your app with instruments.

Starting in iOS 7, iPhone apps emulated on the iPad always launch at 2x. calabash cannot currently interact with such apps in 2x mode (trust us, we’ve tried).

@example Here is an example of how to use this function in your ‘Before` launch hooks.

Before do |scenario|
  launcher = Calabash::Cucumber::Launcher.new
  launcher.relaunch
  # ensure emulated apps are at 1x
  ensure_ipad_emulation_1x

  # do other stuff to prepare the test environment
end

@param [Hash] opts optional arguments to control the interaction with

the 1X/2X buttons

@option opts [Symbol] :lang_code (:en) an Apple compatible

language code

@option opts [Symbol] :wait_after_touch (0.4) how long to

wait _after_ the scale button is touched

@return [void]

@raise [RuntimeError] If the app was not launched with instruments. @raise [RuntimeError] If an unknown language code is passed. @raise [RuntimeError] If the scale button cannot be touched.

# File lib/calabash-cucumber/ipad_1x_2x.rb, line 230
def ensure_ipad_emulation_1x(opts={})
  ensure_ipad_emulation_scale(:emulated_1x, opts)
end
ensure_ipad_emulation_scale(scale, opts={}) click to toggle source

Ensures that iPhone apps emulated on an iPad are displayed at scale.

@note It is recommended that clients call this ‘ensure_ipad_emulation_1x`

instead of this method.

@note If this is not an iPhone app emulated on an iPad, then calling

this method has no effect.

@note In order to use this method, you must allow Calabash to launch

your app with instruments.

Starting in iOS 7, iPhone apps emulated on the iPad always launch at 2x. calabash cannot currently interact with such apps in 2x mode (trust us, we’ve tried).

@see ensure_ipad_emulation_1x

@param [Symbol] scale the desired scale - must be ‘:emulated_1x` or

`:emulated_2x`

@param [Hash] opts optional arguments to control the interaction with

the 1X/2X buttons

@option opts [Symbol] :lang_code (:en) an Apple compatible

language code

@option opts [Symbol] :wait_after_touch (0.4) how long to

wait _after_ the scale button is touched

@return [void]

@raise [RuntimeError] If the app was not launched with instruments. @raise [RuntimeError] If an invalid ‘scale` is passed. @raise [RuntimeError] If an unknown language code is passed. @raise [RuntimeError] If the scale button cannot be touched.

# File lib/calabash-cucumber/ipad_1x_2x.rb, line 167
def ensure_ipad_emulation_scale(scale, opts={})
  return unless iphone_app_emulated_on_ipad?

  unless uia_available?
    raise 'this function requires the app be launched with instruments'
  end

  allowed = [:emulated_1x, :emulated_2x]
  unless allowed.include?(scale)
    raise "'#{scale}' is not one of '#{allowed}' allowed args"
  end

  default_opts = {:lang_code => :en,
                  :wait_after_touch => 0.4}
  merged_opts = default_opts.merge(opts)

  obj = Emulation.new(merged_opts[:lang_code])

  actual_scale = obj.scale

  if actual_scale != scale
    obj.tap_ipad_scale_button
  end

  sleep(merged_opts[:wait_after_touch])

end

Private Instance Methods

_ensure_ipad_emulation_2x(opts={}) click to toggle source

@!visibility private ensures iPhone apps running on an iPad are emulated at 2X

you should never need to call this function - calabash cannot interact with iPhone apps emulated on the iPad in 2x mode.

# File lib/calabash-cucumber/ipad_1x_2x.rb, line 240
def _ensure_ipad_emulation_2x(opts={})
  ensure_ipad_emulation_scale(:emulated_2x, opts)
end