2016-10-10 6 views
0

UITestsで特定の座標にどのように触れることができますか?あなたが唯一の既知の要素を基準として特定の座標をタップすることができ特定の座標をタッチする(UIテスト)

XCUIApplication *app = [[XCUIApplication alloc] init]; 
[[[[[[[[[[app.otherElements containingType:XCUIElementTypeNavigationBar 
identifier:@"Navigation Bar title"] 
childrenMatchingType:XCUIElementTypeOther].element 
childrenMatchingType:XCUIElementTypeOther].element 
childrenMatchingType:XCUIElementTypeOther].element 
childrenMatchingType:XCUIElementTypeOther] elementBoundByIndex:0] 
childrenMatchingType:XCUIElementTypeOther].element 
childrenMatchingType:XCUIElementTypeOther] 
elementBoundByIndex:0].staticTexts[@"Action"] tap]; 
+0

これを改行してください。 – Lumialxk

答えて

2

:私は特定の場所でタップを記録していた場合

、私のようなものを持っています。つまり、座標(20,400)でピクセルをタップすることはできません。代わりに、要素を見つけて、オフセットのあるものをタップする必要があります。

XCUIApplication *app = [[XCUIApplication alloc] init]; 
XCUIElement *label = app.labels[@"Label Name"]; 
XCUICoordinate *coordinate = [label coordinateWithNormalizedOffset(CGVectorMake(0.5, 1.2)); 
[coordinate tap]; 

私は私のUI Testing Cheat Sheetポストにオフセット権利を把握する方法の詳細を文書化。


あなたはちょうどあなたが(代わりに、これらのクエリのすべてとドリルダウンの)直接アクセスすることができActionボタンをタップしようとしている場合。

XCUIApplication *app = [[XCUIApplication alloc] init]; 
[[[app.navigationBars element].staticTexts[@"Action"] tap]; 
1

ウィンドウ要素からXCUICoordinateを構築し、画面の特定の座標をタップします。

XCUIApplication *app = [[XCUIApplication alloc] init]; 
XCUIElement *window = [app.windows elementAtIndex:0]; 
// Get co-ordinate for the top left corner of the screen 
XCUICoordinate *origin = [window coordinateWithNormalizedOffset:CGVectorMake(0.0, 0.0)]; 
// Get coordinate relative to the top left of the screen 
XCUICoordinate *myCoordinate = [origin coordinateWithOffset:CGVectorMake(40.0, 100.0)]; 

[coordinate tap]; 
関連する問題