XCUITest Testing Native Callkit UI Using Springboard. How to get the caller label?

414 Views Asked by At

I am trying to test VOIP calling in our app. I simulate a call and I try to assert if the correct caller ID is present. However, I can't access the caller name label "Bob" using the following:

let springBoard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
XCTAssert(springBoard.staticTexts["Bob‬"].waitForExistence(timeout: 10)) // Assertion fails

However, if I try to access the label just below it "*** Audio…" using the same call the assertion passes:

XCTAssert(springBoard.staticTexts["*** Audio…"].waitForExistence(timeout: 10))

When I print out springBoard.debugDescription I find both "Bob" and "*** Audio…" in the accessibility hierarchy and they both are staticTexts:

Debug Description

The screen being tested:

Native UI Being Tested

How do I go about accessing "Bob" label and asserting that it's the correct caller ID?

1

There are 1 best solutions below

2
cesarmarch On

I met the same kind of issue. I figured it out using NSPredicate with a LIKE instead of using only the name. I think hidden characters are added around the name.

            XCTAssert(springBoard.staticTexts.matching(NSPredicate(format: "label LIKE '*Bob*'")).firstMatch.waitForExistence(timeout: 10))

This works for me and should work for you as well.