Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 7 UITesting for menu bar apps on OS X

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.

like image 304
RapTop Avatar asked Aug 28 '15 15:08

RapTop


1 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.

like image 134
Gaston Avatar answered Sep 21 '22 04:09

Gaston