我正在iOS模拟器中使用UIAutomation进行一些自动化测试。
在Xcode 6中,iOS模拟器的键盘行为改变类似于真正的设备,现在有一个菜单项可以连接/断开Mac的键盘到模拟器:硬件>键盘>连接硬件键盘。
我不介意,但是当你的Mac键盘连接时,模拟器将不再显示软件键盘。当您使用UIAutomation运行测试脚本时,像UIATarget.localTarget().frontMostApp().keyboard().typeString("myString");这样的调用将失败,因为键盘不会出现,即使您已经将文本字段作为第一个响应程序。
这很烦人,因为如果我在模拟器中进行任何手动测试,在运行任何UIAutomation测试之前,我需要记住禁用硬件键盘,否则它们都会失败。
在UIAutomation JS脚本中,有没有检查硬件键盘设置并禁用它们的方法?或者,在执行UIAutomation脚本之前,可以从命令行执行此操作吗?
发布于 2015-02-02 21:51:23
如果我正确理解了你的问题,你需要防弹的方式输入文本。我只是用setValue来做这个。像这样:UIATarget.localTarget().frontMostApp().textFields().Login.setValue('sofa');
发布于 2020-05-01 16:58:40
更新了Leo对Xcode 11的答复,其中将“硬件”更改为"I/O“。为此,Xcode 11.4.1需要一个bash脚本包装器来调用AppleScript scpt文件。
文件
./禁用-硬件-键盘
/禁用-硬件-键盘.
tell application "Simulator"
activate
end tell
tell application "System Events"
set hwKB to value of attribute "AXMenuItemMarkChar" of menu item "Connect Hardware Keyboard" of menu 1 of menu item "Keyboard" of menu 1 of menu bar item "I/O" of menu bar 1 of application process "Simulator"
if ((hwKB as string) is equal to "missing value") then
do shell script "echo 'hardware keyboard is off'"
else
click menu item "Connect Hardware Keyboard" of menu 1 of menu item "Keyboard" of menu 1 of menu bar item "I/O" of menu bar 1 of application process "Simulator"
end if
end tell#!/bin/bash
cd $(dirname $0)
osascript disable-hardware-keyboard.scpt发布于 2018-05-02 16:41:36
因为Ian的脚本在网络中不再可见,所以我的Apple脚本的变体关闭了硬件键盘。
tell application "Simulator"
activate
end tell
tell application "System Events"
set hwKB to value of attribute "AXMenuItemMarkChar" of menu item "Connect Hardware Keyboard" of menu 1 of menu item "Keyboard" of menu 1 of menu bar item "Hardware" of menu bar 1 of application process "Simulator"
if ((hwKB as string) is equal to "missing value") then
do shell script "echo 'hardware keyboard is off'"
else
click menu item "Connect Hardware Keyboard" of menu 1 of menu item "Keyboard" of menu 1 of menu bar item "Hardware" of menu bar 1 of application process "Simulator"
end if
end tellhttps://stackoverflow.com/questions/27973891
复制相似问题