Muthu Sabarinathan
Muthu Sabarinathan

Reputation: 1208

How to test UITableview section and its cells using XCUITests?

Am newbie for Automation testing(XCUITest).

Am writing an UI test case for UITableView. In my scenario I have a grouped tableview like below mentioned image, cell will be loading dynamically based on server response.

enter image description here

I need to write two cases.

Case 1: In "SETTINGS" section have "Rate our app" cell. Some scenarios this "Rate our app" cell comes under "INFORMATION" section. So I need to write a case for checking this. I have to check whether "Rate our app" cell is present in "SETTINGS" section or not.

I set accessibility Identifier for section as "settings-Header-AID" and all cells also set AID like "rateOurApp-Cell-AID".

Case 2: Have to check whether "Rate our app" cell placed after "Report a Bug" cell.

Please guide me to achieve this.

Upvotes: 1

Views: 927

Answers (1)

Václav
Václav

Reputation: 1000

This is not so easy and it depends on your app layout.

Easiest way would be something like this:

let settingsCellLabel = app.collectionViews.cells.element(boundBy: yourSettingsCellPossitionAsInt).label
let reportABugCellLabel = app.collectionViews.cells.element(boundBy: yoursendReportABugCellPossitionAsInt).label
let rateUsCellLabel = app.collectionViews.cells.element(boundBy: yourRateUsCellPossitionAsInt).label

if settingsCellLabel == "Settings" && reportABugCellLabel == "Report a Bug" && rateUsCellLabel == "Rate our App" {
//pass test
} else {
//fail test
}

This way, you are testing if the cells are on same intended possition (you know, that your Rate our App should be on index 5 f.e.) and that it is really them (by checking their label with expected string).

Upvotes: 1

Related Questions