iOS UI 测试 iMessage 应用程序/扩展

标签 ios swift screenshot xcode-ui-testing imessage-extension

我目前正在使用 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/

相关文章:

swift - 类如何符合具有协议(protocol)约束关联类型的协议(protocol)?

java - 截图并保存android

ios - 错误信息 : [MC] Reading from public effective user settings & [MC] System group container for systemgroup. com.apple.configurationprofiles 路径是

ios - iOS 上的 Tapkey Mobile SDK 崩溃 - java.lang.IllegalArgumentException

c# - 我应该为图像和颜色使用公共(public)静态字段吗?

javascript - 使用 HTML5/Canvas/JavaScript 在浏览器中截屏

php - HTML div 截图?

ios - 如何检查 ios 中的 RequestPermissions?

ios - 制作一个 UILabel block 触摸事件到它背后的 UIViews

ios - CGRect 与程序化 GUI 设计中的约束?