2011-07-30 58 views
2

我正在使用UI Automation爲我的應用程序開發測試用例。我需要測試的其中一個操作是將表格放入「編輯」模式,然後重新排序表格中的單元格。如何使用儀器和UI自動化測試重新排序表格?

我可以導航到視圖並點擊我放入導航欄的「編輯」按鈕。

但是,我似乎無法弄清楚如何正確拖動屏幕。

我發現的UIElement即表視圖(app.mainWindow()表()[0])和執行具有一拖:

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

但是,表需要具有的觸摸和抓住單元格的手柄,然後拖動。我看不出如何執行這樣的行動。

任何人都知道如何做到這一點?

回答

1

我有'拖放'幾乎相同的問題。首先,您需要嘗試拖動一個表格,但不是單元格。第二點是超時。像往常一樣,應用程序對拖動有反應(觸摸並保持)。它可以像1或2秒這個操作。嘗試增加dragFromToForDuration的超時參數。對於我的應用程序來說,設置6到8秒就足夠了。

嘗試實現自己的功能,將採取2個參數。第一個參數 - 要拖動的單元格對象。第二個參數 - 您拖動單元格的另一個單元格對象將被刪除。注意,如果兩個對象都將在屏幕上可見,則此功能將起作用只有

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); 
相關問題