2

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?

Essam Ewaisha
  • 439
  • 5
  • 15

1 Answers1

1

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.

cesarmarch
  • 617
  • 4
  • 13
  • Thanks for sharing. This workaround could be used in some cases. However, it is not conclusive as the name we are trying to assert could be a substring of the presented name. (Ex: 'Bobby' would pass the test even though we are looking for 'Bob') – Essam Ewaisha Aug 06 '19 at 10:10
  • You can use `?` instead of `*` which matches only one character instead of many. So, you can use as many `?` as expected to skip hidden characters and it will still work with `Bob` but not with `Bobby`. – cesarmarch Aug 06 '19 at 13:46