Module: Calabash::Cucumber::IPad

Included in:
Operations
Defined in:
lib/calabash-cucumber/ipad_1x_2x.rb

Defined Under Namespace

Classes: Emulation

Instance Method Summary collapse

Instance Method Details

#ensure_ipad_emulation_1x(opts = {}) ⇒ Object

ensures that iPhone apps emulated on an iPad are displayed at 1X.

here is an example of how to use this function in your Before launch hooks:

Before do |scenario|
  @calabash_launcher = Calabash::Cucumber::Launcher.new
  unless @calabash_launcher.calabash_no_launch?
    @calabash_launcher.relaunch
    @calabash_launcher.calabash_notify(self)
    # ensure emulated apps are at 1x
    ensure_ipad_emulation_1x
  end
  # do other stuff to prepare the test environment
end

takes these optional arguments

:lang_code #=> a language code for matching the name of the 'scale' button

:wait_after_touch #=> how long to wait after the ‘scale’ button is touched

the default values are:

:lang_code => :en

:wait_after_touch => 0.4

IMPORTANT if this is not an iphone app emulated on a ipad, then calling this function has no effect.

raises an exception if:

  • the app was not launched with Instruments i.e. there is no run_loop

  • an unknown language code is passed

  • the ‘scale’ button cannot be touched



175
176
177
# File 'lib/calabash-cucumber/ipad_1x_2x.rb', line 175

def ensure_ipad_emulation_1x(opts={})
  ensure_ipad_emulation_scale(:emulated_1x, opts)
end

#ensure_ipad_emulation_scale(scale, opts = {}) ⇒ Object

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

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).

scale must be one of { :emulated_1x | :emulated_2x }

is it is recommended that clients call this convenience method:

ensure_ipad_emulation_1x #=> ensures the app is displayed in 1x mode

takes these optional arguments

:lang_code #=> a language code for matching the name of the 'scale' button

:wait_after_touch #=> how long to wait after the ‘scale’ button is touched

the default values are:

:lang_code => :en

:wait_after_touch => 0.4

IMPORTANT if this is not an iphone app emulated on a ipad, then calling this function has no effect.

raises an exception if:

  • the app was not launched with Instruments i.e. there is no run_loop

  • an invalid scale is passed

  • an unknown language code is passed

  • the ‘scale’ button cannot be touched



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/calabash-cucumber/ipad_1x_2x.rb', line 114

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