Sha256: eca16e773a30f59e3da284615771e26530089fede8d84b66e0483503f17912e0

Contents?: true

Size: 1.54 KB

Versions: 13

Compression:

Stored size: 1.54 KB

Contents

# encoding: utf-8
module Appium::Ios
  # @private
  # class_eval inside a method because class Selenium::WebDriver::Element
  # will trigger as soon as the file is required. in contrast a method
  # will trigger only when invoked.
  def patch_webdriver_element
    Selenium::WebDriver::Element.class_eval do
      # Cross platform way of entering text into a textfield
      def type text
        # enter text then tap window to hide the keyboard.
=begin
Find the top left corner of the keyboard and move up 10 pixels (origin.y - 10)
now swipe down until the end of the window - 10 pixels.
-10 to ensure we're not going outside the window bounds.

Swiping inside the keyboard will not dismiss it.
=end
        # type
        $driver.execute_script %(au.getElement('#{self.ref}').setValue('#{text}');)

        $driver.ignore {
          # wait 5 seconds for keyboard. if the textfield is disabled then
          # setValue will work, however the keyboard will never display
          # because users are normally not allowed to type into it.
          $driver.wait_true(5) do
            $driver.execute_script %(au.mainApp.keyboard().type() !== 'UIAElementNil')
          end

          # dismiss keyboard
          js = <<-JS
            if (au.mainApp.keyboard().type() !== "UIAElementNil") {
              var startY = au.mainApp.keyboard().rect().origin.y - 10;
              var endY = au.mainWindow.rect().size.height - 10;
              au.flickApp(0, startY, 0, endY);
            }
          JS

          $driver.execute_script js
        }
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
appium_lib-0.15.2 lib/appium_lib/ios/patch.rb
appium_lib-0.15.1 lib/appium_lib/ios/patch.rb
appium_lib-0.15.0 lib/appium_lib/ios/patch.rb
appium_lib-0.14.0 lib/appium_lib/ios/patch.rb
appium_lib-0.13.0 lib/appium_lib/ios/patch.rb
appium_lib-0.12.0 lib/appium_lib/ios/patch.rb
appium_lib-0.11.1 lib/appium_lib/ios/patch.rb
appium_lib-0.11.0 lib/appium_lib/ios/patch.rb
appium_lib-0.10.0 lib/appium_lib/ios/patch.rb
appium_lib-0.9.1 lib/appium_lib/ios/patch.rb
appium_lib-0.9.0 lib/appium_lib/ios/patch.rb
appium_lib-0.8.0 lib/appium_lib/ios/patch.rb
appium_lib-0.7.1 lib/appium_lib/ios/patch.rb