Search code examples
iosuitableviewxctestxcode-ui-testing

UI testing get text from uitableviewcell


I'm writting some UI Tests and I'm currently having a problem to match some text that is in a tableview cell.

So I want to test that a tableview has all the cases that it needs to have.

I tried it as follows:

if !app.staticTexts["sometext"].exists {
// FAIL
}

but this doens't work because it doesn't find the text and then I found something like this:

app.tables.cells.staticTexts["some text"].exists

and last but not least like this:

app.tables.cells.containingType(.StaticText, identifier: "some text")

But it seems that the is never finding the text and it is on the screen. Someone knows how to get the text out of a tableview cell?


Solution

  • Set the accessibilityIdentifier on both your UITableViews, then you will be able to choose the right table every time.

    app.tables["myIdentifier"].cells.staticTexts["some text"]