在iOS模拟器上初次启动时关闭警报
我正在为我的应用程序进行自动化UI测试,并且在尝试设置运行测试环境时遇到了问题。该计划大致是这样的:在iOS模拟器上初次启动时关闭警报
- 构建应用程序
- 关机模拟器如果运行
- 删除模拟器做一个干净的安装
- 在模拟器上安装我的应用程序
- 运行UIAutomation测试
除了当仪器启动应用程序以执行测试时,一切正常,警报似乎询问是否用户允许通知。这一切都如预期,但我无法找到摆脱警报的方式。
事情我已经尝试:
- 创建onAlert在我的测试脚本中的第一件事情,如果它出现在我的警惕回调的情况下,定义
- 延迟目标由前5秒实际测试运行,即使之前的应用程序的UI是在模拟器
我也是通过上面所有的排列组合就可见可在SO被发现,我从来没有让我的onAlert调用的回调,不管是什么我做。所以,我想另一件事是:
- 尝试驳回警报使用AppleScript
我写的剧本:
tell application "System Events"
tell process "iOS Simulator"
set allUIElements to entire contents of window 1
repeat with anElement in allUIElements
try
log anElement
end try
end repeat
end tell
end tell
并显示:
static text “MyApp” Would Like to Send You Notifications of window iOS Simulator - iPhone 6 - iPhone 6/iOS 8.1 (12B411) of application process iOS Simulator
static text Notifications may include alerts, sounds, and icon badges. These can be configured in Settings. of window iOS Simulator - iPhone 6 - iPhone 6/iOS 8.1 (12B411) of application process iOS Simulator
UI element 3 of window iOS Simulator - iPhone 6 - iPhone 6/iOS 8.1 (12B411) of application process iOS Simulator
看起来像按钮放置在“UI元素3”中,但我无法从i中检索任何元素放弃它,更不用说点击它了。所以,我有无障碍经理检查:
它坐在那里,作为一个孩子,其他的人都通知的标题和消息。但是,当我去那个元素,突出显示它,我看到:
它认定为一般元素,它没有任何的孩子...... 有趣的是,当我选择在辅助功能检查OK按钮,我可以清楚地看到它的窗口的子窗口,但它永远不会上市:
可有人请阐明这是怎么回事一些轻?我怎样才能用Applescript按下那个按钮?
如果您正在使用Instrument进行自动化,则需要注册回调(onAlert)以对警报执行任何操作。
但您的情况的问题是,警报出现在您的脚本实际开始执行之前,并且此时没有注册警报的回调。
因此,如果警报在启动应用程序时可能延迟约10秒,则只能处理它。但是这只能通过源代码来控制,而不能通过自动化代码来控制。
因此仅剩下的选择是你需要手动解雇一次新的应用程序被安装
,我也面临着同样的问题的警觉,并发现它是工具
有太多的限制许多限制这个工具,这就是为什么我转移到UFT
我有一个类似的问题。我只是想要在警报上的最后一个控件的位置。所以我想出了以下一段代码:
on get_simulator_last_object_rect(simulator_index)
tell application "System Events"
set ProcessList to (unix id of processes whose name is "iOS Simulator")
set myProcessId to item simulator_index of ProcessList
tell window 1 of (processes whose unix id is myProcessId)
-- Forcefully print the UI elements so that Accessibility hierarchy is built
UI elements
-- Then wait precisely to let the Accessibility view hierarchy is ready
delay 0.5
set lowest_label_lowest_position to 0
set _x to 0
set _y to 0
set _width to 0
set _height to 0
repeat with element in UI elements
set {_x, _y} to position of element
set {_width, _height} to size of element
set current_control_lowest_position to _y + _height
if current_control_lowest_position > lowest_label_lowest_position then set lowest_label_lowest_position to current_control_lowest_position - _height/2
end repeat
return {{_x, _y}, {_width, lowest_label_lowest_position}}
end tell
end tell
end get_simulator_alert_ok_button_position
我有一个桌面应用程序来控制我的行为。我在我的桌面应用程序中使用这个苹果脚本来获取最后一个控件的框架。现在我已经有了框架,我创建了一个鼠标事件,并在激活模拟器后单击框架。
尽管我还没有尝试过,但我确信您可以从Apple脚本创建鼠标事件并执行点击帧/帧的中心。
希望这会有所帮助。
谢谢, RKS