There are currently no user interface tests in Xcode for extending the iMessage application. But you can do this by running Messages yourself and finding items in the Messages application. First you need to start the Message application and open a conversation:
let messageApp = XCUIApplication(bundleIdentifier: "com.apple.MobileSMS") messageApp.terminate() messageApp.activate() messageApp.cells.firstMatch.tap()
You can then access your iMessage application by following these steps:
// Replace appIndex by the position of your app in the iMessage bottom bar let appIndex = 2 messageApp.collectionViews.descendants(matching: .cell).element(boundBy: appIndex).tap()
When your iMessage application opens in advanced mode, you can access the close button:
let closeButton = messageApp.buttons.element(boundBy: 1)
If you want to test your iMessage application when a user sends a message and then open it, you can do it like this:
// Send your message after it is inserted in the Messages app text field let sendButton = messageApp.buttons["sendButton"] waitForElementToExists(sendButton) sendButton.tap() // Tap on the iMessage first bubble let firstBubble = messageApp.collectionViews["TranscriptCollectionView"].cells.element(boundBy: 2) waitForElementToExists(firstBubble) firstBubble.tap()
private func waitForElementToExists(_ element: XCUIElement) { let exists = NSPredicate(format: "exists == 1") expectation(for: exists, evaluatedWith: element, handler: nil) waitForExpectations(timeout: 5, handler: nil) }
Benjamin pisano
source share