Ios Xcode 7,UI测试:使用UITableView
我在使用苹果公司在2015年WWDC上推出的xCode的Ios Xcode 7,UI测试:使用UITableView,ios,xcode7,ui-testing,xcode-ui-testing,Ios,Xcode7,Ui Testing,Xcode Ui Testing,我在使用苹果公司在2015年WWDC上推出的xCode的ui测试框架时遇到了一个问题。 我有一个UITableView,这个表包含很多单元格。此外,我还有一个带有单元格标题的NSArray-如果NSArray中包含单元格标题,则应点击此单元格。 我的问题是,我不能滚动特定单元格的表视图,因为框架不包含处理表视图的方法,只包含滑动手势(向下、向上) 也许有人知道如何在表格视图中点击特定单元格?或者如何滚动特定单元格的表格视图? 因为当我为屏幕上看不到的单元格调用tap()方法时,什么都不会发生 提
ui测试
框架时遇到了一个问题。
我有一个UITableView,这个表包含很多单元格。此外,我还有一个带有单元格标题的NSArray-如果NSArray中包含单元格标题,则应点击此单元格。
我的问题是,我不能滚动特定单元格的表视图,因为框架不包含处理表视图的方法,只包含滑动手势(向下、向上)
也许有人知道如何在表格视图中点击特定单元格?或者如何滚动特定单元格的表格视图?
因为当我为屏幕上看不到的单元格调用tap()
方法时,什么都不会发生
提前谢谢 我最近遇到了一个类似的问题。 您可以尝试的一个选项是在表中查找单元格的特定标题,然后点击该标题 例如:-
XCUIApplication().tables.staticTexts["identifier"].tap()
或
其中“identifier”是您尝试点击的单元格的标题
我希望这有帮助 这对我很有用:
XCUIElementQuery *tablesQuery = self.app.tables;
XCUIElementQuery *cellQuery = [tablesQuery.cells containingType:XCUIElementTypeStaticText
identifier:@"Work"];
XCUIElementQuery* cell = [cellQuery childrenMatchingType:XCUIElementTypeStaticText];
XCUIElement* cellElement = cell.element;
[cellElement tap];
要滚动表格,请使用:
XCUIElementQuery *tablesQuery = self.app.tables;
XCUIElement* table = tablesQuery.element;
[table swipeUp];
@Eugene Zhenya Gordin答案的Swift版本: 为Swift 4更新
let tablesQuery = app.tables
let cellQuery = tablesQuery.cells.containing(.staticText, identifier: "MyCell")
let cell = cellQuery.children(matching: .staticText)
let cellElement = cell.element
cellElement.tap()
let tableElement = tablesQuery.element
tableElement.swipeUp()
我也有同样的问题 起初,我只是通过
.staticText
查询点击单元格的标签。这是另一种对我有效的方法:
XCUIElementQuery *tablesQuery = self.app.tables;
XCUIElementQuery *cellQuery = [tablesQuery.cells containingType:XCUIElementTypeStaticText
identifier:@"Work"];
XCUIElementQuery* cell = [cellQuery childrenMatchingType:XCUIElementTypeStaticText];
XCUIElement* cellElement = cell.element;
[cellElement tap];
在实例化单元格的cellforrowatinexpath
中,根据其标题标签或其他属性,为每个单元格指定一个唯一标识符
例如:
cell.accessibilityIdentifier = [NSString stringWithFormat:@"myCellType%@", cell.colorIdentifier];
然后,回到测试类中,尝试以下内容:(故意有点冗长,因为这有助于我更好地理解)
特定的单元格在与之交互时解析
希望有帮助 谢谢您的回复,但它不起作用,点击()后什么也没有发生。:/(.staticText,标识符:“Work”)let cell=cellQuery.children(匹配:.staticText)let cellElement=cell.element cellElement.tap()这些不会在Swift中编译4@delta2flat现在试试
XCUIApplication *application = [XCUIApplication new];
XCUIElementQuery *tablesQuery = application.tables;
XCUIElementQuery *allCellsQuery = tablesQuery.cells;
XCUIElementQuery *specificCellQuery = [cellQuery matchingIdentifier:@"myCellTypeSaffron"];
XCUIElement *cell = specificCellQuery.element;
[cell tap];