iOS/UI 自动化 : UIAActionSheet does not have possibilities to manipulate with buttons

标签 ios instruments ui-automation ios-ui-automation

我的问题与来自 XCode 的 Instruments 工具的 UI 自动化模板有关。 UI 自动化如何支持 UIActionSheet 测试?我知道有一个 UIAActionSheet 元素,我能够在我的应用程序中获取它。但我不知道如何从操作表中获取和操作按钮。 UI 自动化不为这些按钮提供任何元素。 UI 自动化文档也没有关于此事的任何信息。请参阅下面的链接。看起来这个控件没有为按钮使用 UIButton 类,而是以某种特定的方式呈现它们。你能给我一些线索如何从 UIAActionSheet 到达按钮吗?谢谢。

http://developer.apple.com/library/ios/#documentation/ToolsLanguages/Reference/UIAActionSheetClassReference/UIAActionSheet/UIAActionSheet.html#//apple_ref/doc/uid/TP40009895

最佳答案

我已经找到了使用直接攻丝模拟解决问题的方法。这不是一个很好的解决方案,但至少它是有效的。我在苹果开发者论坛上问过同样的问题,但没有得到任何回应。

所以,下面的函数就是我的解决方案。我已经对其进行了测试,并且性能良好。我仍将继续寻找更好的方法。

function tapActionSheetButton(target, actionSheet, buttonIndex)
{
    var headerHeight = 28;
    var buttonHeight = 50;

    if (buttonIndex >= 0) 
    {
        var actionSheetRect = actionSheet.rect();
        UIALogger.logMessage("actionSheet:{rect:{origin:{x:" + actionSheetRect.origin.x.toString() 
                             + ", y:" + actionSheetRect.origin.y.toString()
                             + "}, size:{width:" + actionSheetRect.size.width.toString()
                             + ", height:" + actionSheetRect.size.height.toString()
                             + "}}}");
        var xOffset = actionSheetRect.size.width / 2;
        var yOffset = headerHeight + buttonIndex * buttonHeight + buttonHeight / 2;
        if (yOffset < actionSheetRect.size.height) {
            var tap_x = actionSheetRect.origin.x + xOffset;
            var tap_y = actionSheetRect.origin.y + yOffset;
            target.tap({x:tap_x, y:tap_y});
        }
    }
    else
    {
        var message = "Cannot tap button " + buttonIndex.toString() + ". It does not exist";
        throw message;
    }
}

关于iOS/UI 自动化 : UIAActionSheet does not have possibilities to manipulate with buttons,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5250201/

相关文章:

iphone - UITableView 在 cellForRow 中使用 selectRowAtIndexPath 导致双高亮

java - 实现 selenium webdriver 时如何将表中的 WebElements 列表存储到列表中?

objective-c - 如果未链接到 XCode 或 Instrument,应用程序会崩溃

xcode - 一定时间范围内的时间分析器?

javascript - 从控制台日志隐藏调试消息

ios - Xcode INSTRUMENTS 通过/失败日志记录功能在 Xcode 4.6 中似乎已损坏

ios - 无法根据包含的数字对数组进行排序

iphone - 如何获取 UIButton 的 UIControlTouchDragInside 和 UIControlTouchDragOutside 阈值作为框架?

ios - NotificationCenter 在从 viewcontroller 发布到另一个 ViewController 时第一次不工作

ios - XCODE 6 分配工具不显示自己的类名