【问题标题】:How to automatically click OK in response to "<app> would like to use your current location" while testing with KIF?如何在使用 KIF 进行测试时自动单击“确定”以响应“<app> 想使用您当前的位置”?
【发布时间】:2013-03-21 21:16:54
【问题描述】:

我正在使用 KIF 进行 GUI 测试,我们似乎无法在 Simulator 中自动单击应用程序首次运行时出现的 &lt;app&gt; would like to use your current location 警报中的 OK 按钮。有没有办法配置模拟器或应用程序来绕过该弹出窗口?

【问题讨论】:

    标签: ios ios-simulator kif-framework


    【解决方案1】:

    recent addition 到 KIF 将 -acknowledgeSystemAlert 添加到测试运行器。这可以在模拟器上运行以确认位置服务授权对话框时使用。当请求访问用户的照片库时,可以以相同的方式使用它。

    【讨论】:

    • 有什么使用技巧吗?我试过 [UIAutomationHelper acknowledgeSystemAlert];但是警报仍然在屏幕上 - 它从未被解雇。编辑:我是 iOS 8.3。发行说明声明它仅适用于 iOS 8.1。哦,好吧:(
    【解决方案2】:

    有一个thread about this on the KIF mailing list about a year ago

    由于您这样做只是为了测试,因此很容易调出CLLocationManager 的部分以避免此警报。

    (显然,任何提交到应用商店的代码都会让你匆忙拒绝。)

    [CLLocationManager swizzleInstanceSelector:@selector(startUpdatingLocationFake) toSelector:@selector(startUpdatingLocation)];
    [CLLocationManager swizzleInstanceSelector:@selector(locationFake) toSelector:@selector(location)];
    
    // One for class, one for (deprecated) instance method 
    [CLLocationManager swizzleInstanceSelector:@selector(locationServicesEnabledFake) toSelector:@selector(locationServicesEnabled)];
    [CLLocationManager swizzleClassSelector:@selector(locationServicesEnabledFake) toSelector:@selector(locationServicesEnabled)];
    

    这两个新的类方法定义如下:

    + (void)swizzleInstanceSelector:(SEL)firstSelector toSelector:(SEL)secondSelector;
    {
        Method swizzleMethod = class_getInstanceMethod(self, firstSelector);
        Method method = class_getInstanceMethod(self, secondSelector);
        method_exchangeImplementations(method, swizzleMethod);
    }
    
    + (void)swizzleClassSelector:(SEL)firstSelector toSelector:(SEL)secondSelector;
    {
        Method swizzleMethod = class_getClassMethod(self, firstSelector);
        Method method = class_getClassMethod(self, secondSelector);
        method_exchangeImplementations(method, swizzleMethod);
    }
    

    【讨论】:

    • 嗨,吉姆,我刚刚尝试过,但它不起作用。我的意思是我将 swizzle* 方法作为一个类别添加到 CLLocationManager 中。在我的 main() 函数中运行上面的代码不起作用,当我从我的应用程序委托中调用它时它也不起作用。两者都没有阻止有关“想使用您当前的位置”的弹出窗口。还有其他想法吗?谢谢。
    猜你喜欢
    • 2012-06-16
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多