我正在使用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});

但是,桌子需要触摸并按住单元格的手柄,然后拖动。我看不到如何执行这样的操作。

有人知道该怎么做吗?

最佳答案

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

尝试实现自己的函数,该函数将使用2个参数。第一个参数-您要拖动的单元格对象。第二个参数-您拖动单元格的另一个单元格对象将被放置。注意,如果FROM和TO对象在屏幕上都可见,则此函数仅在上起作用。

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);

10-07 19:55
查看更多