I am trying to use the XCode 7 UITesting for an Menubar app like Dropbox, 1Password on Mac OS X. Is this possible to automate the UI testing using the latest feature offered by Xcode 7? I understand the UI Testing works for an iOS app, but demo never show if it works OS app or not in the video. If it works for an OS X app, but will it works for menubar app? Please guide me through this problem.
-
1I'm having this exact same problem. You can UI Test OSX apps, but if you enable the "Application is agent (UIElement)" option on `Info.plists` then the `XCUIApplication().launch()` stops working. Any ideas? – Gaston Feb 21 '16 at 14:20
2 Answers
I found a better solution to this problem, motivated by this answer: https://stackoverflow.com/a/5384319/96737
Instead of removing the Dock capability from the Info.plist, it's better to set the application's "activation policy" as "accessory" programmatically.
In swift3 via Xcode 8.1:
func applicationDidFinishLaunching(_ aNotification: Notification) {
NSApp.setActivationPolicy(NSApplicationActivationPolicy.accessory)
}
The biggest benefit is that it works in runtime and in UI testing without modifications. You don't need to activate or desactivate the activation policy depending on wether you're running the application inside a UI test or not.
It just works.
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.

- 419
- 5
- 15