我目前正在使用 Fastlane Snapshot自动为我的应用程序截取屏幕截图。这一切都基于 UI 测试。
我正在尝试将相同的功能添加到 iMessage 应用程序/扩展。
所以目前我有一个测试可以通过点击按钮、填写文本字段、截取屏幕截图等。
完成所有操作后,我希望它关闭应用程序(单击主页按钮),打开 iMessage,与我的 iMessage 应用程序交互并在那里截取一些屏幕截图。
这可能吗?如果是这样,我怎样才能做到这一点?为这个应用程序自动截屏真是太棒了,我也希望能够为 iMessage 应用程序做到这一点。
最佳答案
目前 Xcode 中没有针对 iMessage 应用程序扩展的 UI 测试。但是您可以通过自己启动消息并在消息应用程序中查找元素来执行它。首先,您必须启动消息应用程序并打开对话:
let messageApp = XCUIApplication(bundleIdentifier: "com.apple.MobileSMS")
messageApp.terminate()
messageApp.activate()
messageApp.cells.firstMatch.tap()
然后,您可以通过以下方式访问您的 iMessage 应用:
// 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()
当您的 iMessage 应用程序以扩展模式打开时,您可以访问关闭按钮:
let closeButton = messageApp.buttons.element(boundBy: 1)
如果你想在用户发送消息然后打开它时测试你的 iMessage 应用程序,你可以这样做:
// 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)
}
关于iOS UI 测试 iMessage 应用程序/扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44150764/