开发者

How can I test re-ordering a table using Instruments and UI Automation?

I am using UI Automation to develop test cases for my app. One of the actions I need to test is to put a table into 'edit' mode and then re-order cells in the table.

I am able to navigate to the view and tap on the 'edit' button I put into the navigationBar.

However, I cannot seem to figure out how to drag on the screen properly.

I found the UIElement that is the table view (app.mainWindow().tables()[0]) and performed a drag with:

table.dragInsideWithOptions({startOffset:{x:0.8, y:0.3}, end开发者_运维百科Offset:{x:0.8, y:0.8}, duration:1.5});

However, the table needs to have a touch and hold on the cell's handle, then drag. I don't see how to perform such an action.

Anyone figure out how to do this?


I had almost the same problem with 'Drag and Drop'. First of all you need to try to drag not a table but cell in it. The second point is timeout. As usual application has timeout to react on drag (touch and hold). it can be like 1 or 2 seconds for this operation. Try to increase timeout parameter for dragFromToForDuration. For my application it was enough to set 6 - 8 seconds.

Try to implement your own function that will take 2 parameters. First parameter - cell object you want to drag. Second parameter - another cell object where you dragged cell will be dropped. NOTE that this function will work only if both of FROM and TO objects will be visible on the screen.

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

For example you have 5 cells. You need to drag the second one and to put it at the end. Example of function call:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜