class Calabash::Cucumber::IPad::Emulation
@!visibility private Provides methods to interact with the 1x and 2x buttons that appear when an iPhone-only app is emulated on an iPad. Calabash
cannot interact with these apps in 2x mode because the touch coordinates cannot be reliably translated from normal iPhone dimensions to the emulated dimensions.
On iOS < 7, an app remembered its last 1x/2x scale so when it reopened the previous scale would be the same as when it closed. This meant you could manually set the scale once to 1x and never have to interact with the scale button again.
On iOS > 7, the default behavior is that all emulated apps open at 2x regardless of their previous scale.
@note In order to use this class, you must allow Calabash
to launch
your app with instruments.
Constants
- IPAD_1X_2X_BUTTON_LABELS
@!visibility private
Maintainers: when adding a localization, please notice that the keys and values are semantically reversed.
you should read the hash as:
“‘ :emulated_1x <= what button is showing when the app is emulated at 2X? :emulated_2x <= what button is showing when the app is emulated at 1X? “`
Attributes
@!visibility private @!attribute [r] lang_code
The Apple compatible language code for determining the accessibility label of the 1X and 2X buttons.
@return [Symbol] Returns the language code of this emulation.
@!visibility private @!attribute [r] scale The current 1X or 2X scale represented as a Symbol.
@return [Symbol] Returns this emulation’s scale. Will be one of ‘{:emulated_1x | :emulated_2x}`.
Public Class Methods
@!visibility private Creates a new Emulation
. @param [Symbol] lang_code
an Apple compatible language code @return [Emulation] Returns an emulation that is ready for action!
# File lib/calabash-cucumber/ipad_1x_2x.rb, line 81 def initialize (lang_code=:en) @button_names_hash = IPAD_1X_2X_BUTTON_LABELS[lang_code] if @button_names_hash.nil? raise "could not find 1X/2X buttons for language code '#{lang_code}'" end @lang_code = lang_code @scale = _internal_ipad_emulation_scale end
Public Instance Methods
Private Instance Methods
@!visibility private
# File lib/calabash-cucumber/ipad_1x_2x.rb, line 106 def _internal_ipad_emulation_scale hash = @button_names_hash val = nil hash.values.each do |button_name| res = uia_call_windows([:view, {:marked => "#{button_name}"}], :name) if res == button_name val = button_name break end end if val.nil? raise "could not find iPad scale button with '#{hash.values}'" end if val == hash[:emulated_1x] :emulated_1x elsif val == hash[:emulated_2x] :emulated_2x else raise "unrecognized emulation scale '#{val}'" end end