【问题标题】:How can I test re-ordering a table using Instruments and UI Automation?如何使用 Instruments 和 UI 自动化测试重新排序表?
【发布时间】:2012-07-09 19:37:27
【问题描述】:

我正在使用 UI 自动化为我的应用开发测试用例。我需要测试的操作之一是将表格置于“编辑”模式,然后重新排列表格中的单元格。

我能够导航到视图并点击我放入导航栏中的“编辑”按钮。

但是,我似乎无法弄清楚如何在屏幕上正确拖动。

我发现 UIElement 是表视图 (app.mainWindow().tables()[0]) 并执行了拖动:

table.dragInsideWithOptions({startOffset:{x:0.8, y:0.3}, endOffset:{x:0.8, y:0.8}, duration:1.5});

但是,表格需要触摸并按住单元格的句柄,然后拖动。我不知道如何执行这样的操作。

有人知道怎么做吗?

【问题讨论】:

    标签: ios ios-ui-automation


    【解决方案1】:

    我在使用“拖放”时遇到了几乎相同的问题。首先,您需要尝试拖动的不是表格而是单元格。第二点是超时。像往常一样,应用程序对拖动(触摸并按住)有超时反应。此操作可能需要 1 或 2 秒。尝试增加 dragFromToForDuration 的超时参数。对于我的应用程序,设置 6 - 8 秒就足够了。

    尝试实现您自己的函数,该函数将采用 2 个参数。第一个参数 - 要拖动的单元格对象。第二个参数 - 您拖动单元格的另一个单元格对象将被删除。请注意,此功能FROMTO 对象都在屏幕上可见的情况下起作用。

    function reorderCellsInTable(from, to)
    {
        if ( from.checkIsValid() && to.checkIsValid() )
        {
            if ( !from.isVisible() )
            {
                from.scrollToVisible();
                //put 1 second delay if needed
            }
            var fromObjRect = from.rect();
            // setting drag point into the middle of the cell. You may need to change this point in order to drag an object from required point. 
            var sourceX = fromObjRect.origin.x + fromObjRect.size.width/2;
            var sourceY = fromObjRect.origin.y + fromObjRect.size.height/2;
            var toObjRect = to.rect();
            // setting drop point into the middle of the cell. The same as the drag point - you may meed to change the point to drop bellow or above the drop point
            var destinationX = toObjRect.origin.x + toObjRect.size.width/2;
            var destinationY = toObjRect.origin.y + toObjRect.size.height/2;
    
            UIATarget.localTarget().dragFromToForDuration({x:sourceX, y:sourceY}, {x:destinationX, y:destinationY}, 8);
            }
        }
    

    例如,您有 5 个单元格。您需要拖动第二个并将其放在最后。函数调用示例:

    var cellToReorder = tableView()[<your table view>].cells()[<cell#2NameOrIndex>];
    var cellToDrop = tableView()[<your table view>].cells()[<cell#5NameOrIndex>];
    reorderCellsInTable(cellToReorder, cellToDrop);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-30
      • 1970-01-01
      • 2017-10-22
      • 1970-01-01
      • 2010-11-24
      • 1970-01-01
      • 2010-11-23
      • 1970-01-01
      相关资源
      最近更新 更多