在iOS上取消appium测试中的键盘

在iOS上取消appium测试中的键盘,appium,Appium,在iOS上的Appium测试中,如何排除键盘?输入文本后,我在控制台中获得此条目 [INSTSERVER] Sending command to instruments: if (!au.mainApp().keyboard().isNil()) { var key = au.mainApp().keyboard().buttons()['Done'] if (key.isNil()) { var startY = au.mainApp().keyboard().rect().o

在iOS上的Appium测试中,如何排除键盘?输入文本后,我在控制台中获得此条目

[INSTSERVER] Sending command to instruments: if (!au.mainApp().keyboard().isNil()) {
  var key = au.mainApp().keyboard().buttons()['Done']
  if (key.isNil()) {
    var startY = au.mainApp().keyboard().rect().origin.y - 10;
    var endY = au.mainWindow().rect().size.height - 10;
    au.flickApp(0, startY, 0, endY);
  } else {
    key.tap();
  }
  au.delay(1000);
}
我可以看到它是假设我的键盘上的按钮是“完成”的,它是“返回”。查看文档后,我应该能够按照以下方式完成此操作

我已使用以下代码尝试此操作:

When(/^I enter the text "(.*?)"$/) do |user_text|
  textfield( "My Textbox" ).type user_text
  hide_keyboard( "Return" )
end
尽管如此,它仍然挂起寻找“完成”按钮。如何覆盖Appium查找的键。我已在此处上载了一个Git存储库,其中包含我的代码:


当我使用“完成”作为键盘按钮返回时,它可以工作。问题是我的应用程序没有使用“完成”。

我最终设法解决了这个问题,通过像这样修补Appium中的键盘代码

功能/支持/env.rb

module Appium
  module Ios
    def patch_webdriver_element
      Selenium::WebDriver::Element.class_eval do
        # Enable access to iOS accessibility label
        # accessibility identifier is supported as 'name'
        def label
          self.attribute('label')
        end

        # Cross platform way of entering text into a textfield
        def type text

          $driver.execute_script %(au.getElement('#{self.ref}').setValue('#{text}');)
        end 
      end 
    end 

    def hide_ios_keyboard close_key='Done'
      dismiss_keyboard = (<<-JS).strip
      if (!au.mainApp().keyboard().isNil()) {
        var key = au.mainApp().keyboard().buttons()['#{close_key}']
        if (key.isNil()) {
          var startY = au.mainApp().keyboard().rect().origin.y - 10;
          var endY = au.mainWindow().rect().size.height - 10;
          au.flickApp(0, startY, 0, endY);
        } else {
          key.tap();
        }
      }
      JS

      ignore do
        wait_true(5) do
          execute_script '!au.mainApp().keyboard().isNil()'
        end

        # dismiss keyboard
        execute_script dismiss_keyboard
      end

      wait_true(5) do
        execute_script 'au.mainApp().keyboard().isNil()'
      end
    end
  end 
end 
def enter_postcode( postcode )
  textfield( "postcode" ).type postcode
  hide_ios_keyboard('Return')
end