Tests iOS UI iMessage App / Extension

I am currently using Fastlane Snapshot to automate taking screenshots for my application. All this is based on user interface tests.

I am trying to add the same functionality to an iMessage / Extension application.

So, currently I have a test that goes through the taps buttons, fills in text fields, takes screenshots, etc.

After all this, I want to close the application (click the "Home" button), open iMessage, interact with my iMessage application and take some screenshots there.

Is it possible? If so, how can I achieve this? The screenshot automation for this application was awesome, and I would love to be able to do it for the iMessage application.

+8
ios swift xcode-ui-testing screenshot imessage-extension
source share
2 answers

With Xcode 9, you can easily switch to other applications, such as Messages. The following code switches to Messages, interacts with elements in the application, and then switches back to your own application.

let messageApp = XCUIApplication(bundleIdentifier: "com.apple.MobileSMS") messageApp.terminate() messageApp.activate() messageApp.cells.staticTexts["Kate Bell"].tap() XCUIApplication().activate() 
0
source share

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) } 
0
source share

All Articles