3

我的 KIF 测试打开了可访问性检查器(显然 KIF 需要它才能工作。)问题是,它的窗口遮挡了一些后续 UI 测试需要点击的控件,而这些测试失败了。

当我的 KIF 测试完成后,如何关闭 Accessibility Inspector 以便我的 UI 测试可以运行?

(从模拟器的设置应用程序中“手动”关闭它不是一个解决方案——我正在寻找可以从代码中调用、在目标中设置或......?)

4

2 回答 2

1

默认情况下未启用。您必须手动打开它。

于 2015-12-28T21:15:43.977 回答
1

我在Stew Gleadow 的博客上看到了以下内容。

您只需要更改行:

CFPreferencesSetValue(CFSTR("ApplicationAccessibilityEnabled"), kCFBooleanFalse, accessibilityDomain, kCFPreferencesAnyUser, kCFPreferencesAnyHost); 

更改kCFBooleanTruekCFBooleanFalse.

+ (void)_enableAccessibilityInSimulator {
    NSAutoreleasePool *autoreleasePool = [[NSAutoreleasePool alloc] init];
    NSString *appSupportLocation = @"/System/Library/PrivateFrameworks/AppSupport.framework/AppSupport";

    NSDictionary *environment = [[NSProcessInfo processInfo] environment];
    NSString *simulatorRoot = [environment objectForKey:@"IPHONE_SIMULATOR_ROOT"];
    if (simulatorRoot) {
        appSupportLocation = [simulatorRoot stringByAppendingString:appSupportLocation];
    }

    void *appSupportLibrary = dlopen([appSupportLocation fileSystemRepresentation], RTLD_LAZY);

    CFStringRef (*copySharedResourcesPreferencesDomainForDomain)(CFStringRef domain) = dlsym(appSupportLibrary, "CPCopySharedResourcesPreferencesDomainForDomain");

    if (copySharedResourcesPreferencesDomainForDomain) {
        CFStringRef accessibilityDomain = copySharedResourcesPreferencesDomainForDomain(CFSTR("com.apple.Accessibility"));

        if (accessibilityDomain) {
            CFPreferencesSetValue(CFSTR("ApplicationAccessibilityEnabled"), kCFBooleanFalse, accessibilityDomain, kCFPreferencesAnyUser, kCFPreferencesAnyHost);
            CFRelease(accessibilityDomain);
        }
    }

    [autoreleasePool drain];
}
于 2016-05-08T22:40:10.237 回答