简体   繁体   中英

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM