【问题标题】:XCUITest using adjustToPickerWheelValue: && viewForRow: delegate results in assertionXCUITest 使用 adjustToPickerWheelValue: && viewForRow: 委托导致断言
【发布时间】:2017-05-27 19:59:55
【问题描述】:

我遇到了这样一种情况,在没有生成断言的情况下,我无法让包含 UIPickerView 的视图控制器工作的 XCUITest。导致断言的问题显然是由于 XCUITest 使用的可访问性功能将虚假的“n 中的 1”附加到每个选择器值。

像这一行这样简单的东西会在测试期间断言

[app.pickers.pickerWheels.element adjustToPickerWheelValue:@"ANYVALUE"];

这原来是 Xcode 的一个已知错误,并且有一个开放的雷达Cannot use UI Testing to adjust pickerView which uses a view-based delegate

这正是我的问题,因为我使用 viewForRow: 委托以便在选择器值中使用属性字符串。使用 titleForRow: 委托的替代方法不会出现问题。

我曾尝试通过手动设置辅助功能信息来解决此问题,但无济于事。

由于我的客户对属性文本的要求,我不能考虑使用 titleForRow: 委托。

然而,作为另一个客户要求,还要为所有视图提供完整的 XCUITests。

有哪些可行的解决方法?

【问题讨论】:

    标签: objective-c xcode8 uipickerview xcode-ui-testing


    【解决方案1】:

    这是 Xcode 中的一个已知 bug,它已经打开了一段时间,至少可以追溯到 2015 年 Apple Developer Forum Post

    显然没有修复。

    为了满足所有客户要求,我的解决方案是创建一个名为“Testing”的附加构建配置,它是从“Debug”复制而来的,以便我可以定义一个新的预处理器宏 XCUITEST。然后在 Test 下编辑方案以使用这个新的构建配置,而不是 DEBUG 或 RELEASE。

    通过这一更改,我可以合并适用于 XC 测试的委托,同时保留满足客户端应用要求的委托,如下所示:

    #ifndef XCUITEST  // for release or debug we use this method as we want attributed text strings
    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
    
    // blah blah
    
    }
    #endif
    
    #ifdef XCUITEST  // for testing we have to use this method so XCUITests will work with adjustToPickerWheelValue:
    - (UIView *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    
    // blah blah
    
    }
    #endif 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 2015-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多