Module: Calabash::Cucumber::IPad

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

Overview

Contains methods for interacting with the iPad.

Instance Method Summary collapse

Instance Method Details

#ensure_ipad_emulation_1x(opts = {}) ⇒ void

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.

This method returns an undefined value.

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

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

Examples:

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

Parameters:

  • opts (Hash) (defaults to: {})

    optional arguments to control the interaction with the 1X/2X buttons

Options Hash (opts):

  • :lang_code (Symbol) — default: :en

    an Apple compatible language code

  • :wait_after_touch (Symbol) — default: 0.4

    how long to wait after the scale button is touched

Raises:

  • (RuntimeError)

    If the app was not launched with instruments.

  • (RuntimeError)

    If an unknown language code is passed.

  • (RuntimeError)

    If the scale button cannot be touched.



230
231
232
# 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 = {}) ⇒ void

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.

This method returns an undefined value.

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

Parameters:

  • scale (Symbol)

    the desired scale - must be :emulated_1x or :emulated_2x

  • opts (Hash) (defaults to: {})

    optional arguments to control the interaction with the 1X/2X buttons

Options Hash (opts):

  • :lang_code (Symbol) — default: :en

    an Apple compatible language code

  • :wait_after_touch (Symbol) — default: 0.4

    how long to wait after the scale button is touched

Raises:

  • (RuntimeError)

    If the app was not launched with instruments.

  • (RuntimeError)

    If an invalid scale is passed.

  • (RuntimeError)

    If an unknown language code is passed.

  • (RuntimeError)

    If the scale button cannot be touched.

See Also:



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# 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