I am trying to write a UI test for our app's IAP using a sandbox account. However, when trying to tap this purchase button, the test is unable to find this element:screenshot of in-app-purchase prompt
I've tried targeting this element by its button name and label name with no success. During the UI recording, when tapping this button, Xcode freezes completely and I am forced to shut Xcode down. I've also tried debugging at this step and when I print out "app.debugDescription" in the console, this button nor any of the other elements in this purchase drawer is returned.
Failing line of code:
app.buttons["Purchase"].tap()
Error message:
No matches found for Elements matching predicate '"Purchase" IN identifiers'
Xcode Version: 13.2.1 iOS Version tested (real iPhone device): 15.3.1
Through trial and error, I've discovered that you can target the purchase button through the SpringBoard.
let springBoard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
springBoard.buttons["Purchase"] // A match will return