你如何解雇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);
}
我可以看到它是假设的按钮“完成”我的键盘上是“回归”。 望着文件我应该能够做到这一点通过以下方式https://github.com/appium/ruby_lib/blob/ef20cdd09cdb3dac32b789144b17ed2daf745a8d/docs/ios_docs.md#hide_keyboard
我曾尝试使用这个下面的代码:
When(/^I enter the text "(.*?)"$/) do |user_text|
textfield( "My Textbox" ).type user_text
hide_keyboard( "Return" )
end
尽管它仍然挂起寻找“完成”按钮。 你如何重写哪个键Appium查找。 我已上载这里与我的代码一个Git仓库: GitHub的库
当我使用“完成”的键盘按钮,返回它的工作原理。 问题是我的应用程序不使用“完成”。
我设法诉诸修补这样在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