小编Vin*_*pai的帖子

Xcode UI测试 - UI测试失败 - 点击搜索字段"取消"按钮时无法滚动显示(通过AX操作)

我试图通过点击搜索栏中的"取消"按钮来关闭搜索字段.

测试用例未能找到取消按钮.它在Xcode 7.0.1中运行良好

我添加了谓词等待按钮出现.当我们点击"取消"按钮时,测试用例失败

let button = app.buttons[“Cancel”]
let existsPredicate = NSPredicate(format: "exists == 1")

expectationForPredicate(existsPredicate, evaluatedWithObject: button, handler: nil)
waitForExpectationsWithTimeout(5, handler: nil)

button.tap() // Failing here
Run Code Online (Sandbox Code Playgroud)

日志:

    t =     7.21s     Tap SearchField
t =     7.21s         Wait for app to idle
t =     7.29s         Find the SearchField
t =     7.29s             Snapshot accessibility hierarchy for com.test.mail
t =     7.49s             Find: Descendants matching type SearchField
t =     7.49s             Find: Element at index 0
t =     7.49s             Wait for app to idle …
Run Code Online (Sandbox Code Playgroud)

xcode xcode7 xcode-ui-testing

70
推荐指数
3
解决办法
2万
查看次数

在10.9上以编程方式启用辅助设备的访问

我想在10.9上以编程方式启用对辅助设备的访问.在10.8及更低版本中,我使用以下Applescript来启用辅助设备的访问:

tell application "System Events"
if UI elements enabled is false then
    set UI elements enabled to true
end if
end tell
Run Code Online (Sandbox Code Playgroud)

凭借10.9,Apple已将可访问性选项移至系统偏好设置➞安全和隐私➞隐私➞辅助功能.与以前版本的OS X(对所有应用程序使用通用复选框)不同,10.9中的新功能允许用户单独选择哪些应用程序可以控制系统以执行其各种脚本功能.

关于可访问性的新系统首选项

Apple尚未向开发人员提供任何API,以便以编程方式为应用程序启用辅助功能.因此,当应用程序使用辅助功能API时,Mac OS 10.9将提示最终用户权限的对话框以启用辅助功能.此外,用户必须在启用辅助功能后重新启动应用程序.

Xcode为10.9 OS提供的默认提示对话框

我们可以使用Applescript或任何其他API以编程方式在10.9上启用对辅助设备的访问吗?任何帮助解决这个问题将不胜感激.

macos cocoa accessibility objective-c accessibility-api

38
推荐指数
5
解决办法
2万
查看次数

如何在NSMenu打开时更新它?

我有一个动态添加NSMenuItems的NSMenu.NSMenu在保持打开状态时不能正常刷新.我正在调用NSMenu更新方法NSEventTrackingRunLoopModes.

我已经实现了以下方法来更新NSMenu.

- (void)menuNeedsUpdate:(NSMenu *)menu {
for (NSInteger index = 0; index < count; index++)
    [self menu:menu updateItem:[menu itemAtIndex:index] 
                       atIndex:index 
                  shouldCancel:NO];
}

- (BOOL)menu:(NSMenu *)menu updateItem:(NSMenuItem *)item atIndex:(NSInteger)index shouldCancel:(BOOL)shouldCancel`

- (NSInteger)numberOfItemsInMenu:(NSMenu *)menu
Run Code Online (Sandbox Code Playgroud)

cocoa objective-c nsmenu nsmenuitem nsstatusbar

6
推荐指数
2
解决办法
2875
查看次数

" - (bool)validateToolbarItem:(NSToolbarItem*)theItem"的冲突类型

我有这个代码:

- (BOOL) validateToolbarItem:(NSToolbarItem *)theItem {
    BOOL enable = NO;

    if (1 == [theItem tag]) {
        enable = YES;
    }

    return enable; 
}
Run Code Online (Sandbox Code Playgroud)

虽然程序按预期运行,但我收到此警告:

Conflicting types for '-(bool)validateToolbarItem:(NSToolbarItem *)theItem'
Run Code Online (Sandbox Code Playgroud)

我怎么能摆脱这个警告?谢谢.

macos cocoa objective-c

1
推荐指数
1
解决办法
538
查看次数