I'm trying to implement a very simple test, but I'm stuck with XCUIElementQuery.matching(identifier:) method. I think querying UIImageView
s is not working as expected, but not sure why.
I have these two settings set for views:
And I have this test:
func testRecording() {
XCTAssertEqual(app.staticTexts.matching(identifier: "label").count, 2)
XCTAssertEqual(app.images.matching(identifier: "accept").count, 1)
}
where I'm querying for these two views (Label with id label
and UIImageView with id accept
). From here: app
is simply defined as class property like this: let app = XCUIApplication()
.
So, this is what screen looks like:
This means that this test should pass since there are two staticText
s with id label
and one image
with id accept
on screen. staticText
s are being successfully queried, but it is failing when matching(identifier:)
tries to query image
with id accept
:
I tried to query with many things, like:
app.images.
app.tables.
app.tables.images.
app.tables.cells.images.
app.buttons.
(also marked as Button
in Traits part of the Accessibility settings)app.staticTexts.
(also marked as Static Text
in Traits part of the Accessibility settings)but no luck... Is there anything that I'm doing wrong here, or missing something?
OK, since I'm in the QA team, I haven't looked much to the dev code. But when I did, I found the answer.
UIImageView that is used for displaying check mark is never being used from .xib file, but instead is always allocated a new instance like this:
indicatorView = UIImageView(image: #imageLiteral(resourceName: "arrow_marked_ok_small"))
meaning that new accessibility options are set with initializer call, so that old UIImageView instance that has accessibility options from .xib file I posted in first two images is being overridden.