LoginSignup
0
1

More than 5 years have passed since last update.

XCTestのUITestでCellをタップさせる方法

Last updated at Posted at 2018-01-18

概要

XCTestのUITestでCellをタップさせる方法がわからなかったので、経緯とともに自分用に残しておく。

答え

Cell自体をタップするのではなく、子要素をタップする。

サンプル
- (void)testExample {
    XCUIApplication *app = [[XCUIApplication alloc] init];
    // CellをタップするとNG
    [[app.collectionViews.cells elementBoundByIndex:0] tap];

    // Cellの子要素をタップするとOK
    [[app.collectionViews.cells elementBoundByIndex:0].staticTexts[@"タイトル"] tap];
}

おまけ

上記の例ではタイトルというラベルがあることが前提になっているが、ラベルの文字列が固定じゃない場合は、indexで指定することも可能。

サンプル
- (void)testExample {
    XCUIApplication *app = [[XCUIApplication alloc] init];
    [[[app.tables.cells elementBoundByIndex:0].staticTexts elementBoundByIndex:0] tap];
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1