我正在尝试将 XCode 7 UITesting 用于 Dropbox 等菜单栏应用程序,Mac OS X 上的 1Password。这是否可以使用 Xcode 7 提供的最新功能自动化 UI 测试?我了解 UI 测试适用于 iOS 应用程序,但演示从未在视频中显示它是否适用于操作系统应用程序。如果它适用于 OS X 应用程序,但它适用于菜单栏应用程序吗?请指导我解决这个问题。
2 回答
受此答案的启发,我找到了解决此问题的更好方法:https ://stackoverflow.com/a/5384319/96737
与其从 Info.plist 中删除 Dock 功能,不如以编程方式将应用程序的“激活策略”设置为“附件”。
通过 Xcode 8.1 在 swift3 中:
func applicationDidFinishLaunching(_ aNotification: Notification) {
NSApp.setActivationPolicy(NSApplicationActivationPolicy.accessory)
}
最大的好处是它无需修改即可在运行时和 UI 测试中工作。您无需根据是否在 UI 测试中运行应用程序来激活或停用激活策略。
它只是工作。
I realize this question is very old, but wanted to share my answer.
I created a duplicate of my Info.plist file w/ LSUIElement
set to NO
. I then created a new "UITesting" configuration and pointed its INFOPLIST_FILE
build setting to the duplicate. A better option would've been to create a user-defined build setting and then assign that setting's value to LSUIElement
, but Xcode doesn't allow it w/ Booleans.
Once you've got the UITesting configuration set up, you can edit your scheme to use this configuration during tests.