Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 7, UI-Testing: working with UITableView

I'm facing with one problem using UITesting framework for the xCode that Apple has introduced at WWDC 2015. I have a UITableView and this table contains a lot of cells. Also I have a NSArray with cells titles - if cell title is contained in NSArray this cell should be tapped. My problem is that I can't scroll table view for particular cell, because framework doesn't contain method for working with table views, only swipe gestures (down, up).

Maybe somebody knows how I can tap on particular cell in table view? Or how I can scroll table view for particular cell? Because when I call tap() method for cell which are not visible at screen - nothing happen.

Thanks in advance!

like image 225
Aleh Sarochych Avatar asked Sep 14 '15 10:09

Aleh Sarochych


People also ask

How to perform UI testing in Swift?

Go to File > New > Target. Then, search for UI Testing Bundle. Select Unit Testing Bundle and then click Next. As UI tests take time, it is usually best to stop immediately when a failure occurs.

Which test framework does XCUITest use?

XCUITest is an iOS testing framework developed by Apple in 2015 for its native UI suite. It is developed on top of the XCTest framework which is the main test framework that is integrated within Apple's Xcode. The XCUITest tests can be written on XCode, using Swift or Objective-C.

What is the difference between XCTest and XCUITest?

XCTest / XCUITest is pure iOS and cannot help the team that needs to test both iOS and Android devices. XCUITest was built for the iOS and Xcode Developer in mind and focuses less on the QA Automation Engineer.


2 Answers

This worked for me:

XCUIElementQuery *tablesQuery = self.app.tables;

XCUIElementQuery *cellQuery = [tablesQuery.cells containingType:XCUIElementTypeStaticText
                                                     identifier:@"Work"];

XCUIElementQuery* cell = [cellQuery childrenMatchingType:XCUIElementTypeStaticText];

XCUIElement* cellElement = cell.element;

[cellElement tap];

For scrolling the table use:

XCUIElementQuery *tablesQuery = self.app.tables;
XCUIElement* table = tablesQuery.element;
[table swipeUp];
like image 183
Eugene Gordin Avatar answered Oct 03 '22 19:10

Eugene Gordin


I recently came across a similar problem. An option you can try is to look for a specific title for a cell in the table, and tap on that,

for example:-

XCUIApplication().tables.staticTexts["identifier"].tap()

or

XCUIApplication().tables.cells.staticTexts["identifier"].tap()

Where "identifier" is the title of the cell you are trying to tap.

I hope this helps!

like image 35
Anant Goel Avatar answered Oct 03 '22 17:10

Anant Goel