lib/calabash-cucumber/keyboard_helpers.rb in calabash-cucumber-0.11.5.pre3 vs lib/calabash-cucumber/keyboard_helpers.rb in calabash-cucumber-0.11.5.pre5

- old
+ new

@@ -309,11 +309,11 @@ _ensure_can_enter_text({:screenshot => should_screenshot, :skip => (not should_screenshot)}) if uia_available? if chr.length == 1 - uia_type_string chr + uia_type_string_raw chr else code = UIA_SUPPORTED_CHARS[chr] unless code raise "typing character '#{chr}' is not yet supported when running with Instruments" @@ -323,14 +323,12 @@ # on iOS 7, the Delete char code is \b on non-numeric keyboards # on numeric keyboards, it is actually a button on the # keyboard and not a key if code.eql?(UIA_SUPPORTED_CHARS['Delete']) uia("uia.keyboard().elements().firstWithName('Delete').tap()") - elsif code.eql?(UIA_SUPPORTED_CHARS['Return']) - tap_keyboard_action_key else - uia_type_string(code, '') + uia_type_string_raw(code) end end # noinspection RubyStringKeysInHashInspection res = {'results' => []} else @@ -377,10 +375,60 @@ end end end end + # @!visibility private + # + # Enters text into view identified by a query + # + # @note + # *IMPORTANT* enter_text defaults to calling 'setValue' in UIAutomation + # on the text field. This is fast, but in some cases might result in slightly + # different behaviour than using `keyboard_enter_text`. + # To force use of `keyboard_enter_text` in `enter_text` use + # option :use_keyboard + # + # @param [String] uiquery the element to enter text into + # @param [String] text the text to enter + # @param [Hash] options controls details of text entry + # @option options [Boolean] :use_keyboard (false) use the iOS keyboard + # to enter each character separately + # @option options [Boolean] :wait (true) call wait_for_element_exists with uiquery + # @option options [Hash] :wait_options ({}) if :wait pass this as options to wait_for_element_exists + def enter_text(uiquery, text, options = {}) + default_opts = {:use_keyboard => false, :wait => true, :wait_options => {}} + options = default_opts.merge(options) + wait_for_element_exists(uiquery, options[:wait_options]) if options[:wait] + touch(uiquery, options) + wait_for_keyboard + if options[:use_keyboard] + keyboard_enter_text(text) + else + fast_enter_text(text) + end + end + + # @!visibility private + # + # Enters text into current text input field + # + # @note + # *IMPORTANT* fast_enter_text defaults to calling 'setValue' in UIAutomation + # on the text field. This is fast, but in some cases might result in slightly + # different behaviour than using `keyboard_enter_text`. + # @param [String] text the text to enter + def fast_enter_text(text) + _ensure_can_enter_text + if uia_available? + uia_set_responder_value(text) + else + keyboard_enter_text(text) + end + end + + # Touches the keyboard action key. # # The action key depends on the keyboard. Some examples include: # # * Return @@ -393,19 +441,10 @@ # Not all keyboards have an action key. For example, numeric keyboards # do not have an action key. # # @raise [RuntimeError] if the text cannot be typed. def tap_keyboard_action_key - if uia_available? - run_loop = Calabash::Cucumber::Launcher.launcher.run_loop - if run_loop[:uia_strategy] == :host - uia_type_string "\\\\n", '', false - else - uia_type_string '\n', '', false - end - else - keyboard_enter_char 'Return' - end + keyboard_enter_char 'Return' end # @deprecated 0.10.0 replaced with `tap_keyboard_action_key` # @see #tap_keyboard_action_key #