【问题标题】:String with unicode doesn't match on new XCode UI Test and the test fails带有 unicode 的字符串在新的 XCode UI 测试中不匹配并且测试失败
【发布时间】:2015-09-25 11:37:10
【问题描述】:

我正在使用新的 XCode 7 进行一些 UI 测试。我的应用程序如何使用通知,第一次使用 iOS 时会自动询问“我的应用程序”希望向您发送通知。

当我记录测试时,XCode 在下面写下这些行:

- (void)testFirstUse {
    [XCUIDevice sharedDevice].orientation = UIDeviceOrientationPortrait;

    XCUIApplication *app = [[XCUIApplication alloc] init];
    [app.alerts[@"\U201cMyApp\U201d Would Like to Send You Notifications"].collectionViews.buttons[@"OK"] tap];
    [app.tables/*@START_MENU_TOKEN@*/.staticTexts[@"United States"]/*[[".cells.staticTexts[@\"United States\"]",".staticTexts[@\"United States\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/ tap];
    [app.navigationBars[@"Select a Country"].buttons[@"Next"] tap];

}

请注意,XCode 将 unicode 而不是引号信号放在 MyApp 名称上。 当运行测试失败并出现错误“No matches found for alert”。

我尝试将 unicode 更改为引用信号,但它也不起作用。

清楚吗? 有人有同样的问题吗?

[更新] 我对这段代码有两个问题

1- XCode 生成的带有 unicode 的消息存在错误

2- 点击系统显示的警报后测试失败

【问题讨论】:

    标签: objective-c unicode xcode7 xcode-ui-testing


    【解决方案1】:

    我找到了一种解决方法,以避免在关闭系统警报后崩溃:

    我改变了这一行

    [app.alerts[@"\U201cMyApp\U201d Would Like to Send You Notifications"].collectionViews.buttons[@"OK"] tap];
    

    XCUIElement *alert = app.alerts[@"\U0000201cMyApp\U0000201d Would Like to Send You Notifications"].collectionViews.buttons[@"OK"];    
    if ([alert exists]) {
        [alert tap];
    }
    

    我做了两个改动

    • unicode 上的四个 0000 以避免构建失败
    • 在点击警报之前进行验证以避免测试失败

    【讨论】:

    • 如果显示警报,我仍然会崩溃。
    【解决方案2】:

    您可以通过直接访问alert.element 并通过集合视图点击“确定”按钮来确认警报。

    let app = XCUIApplication()
    app.launch()
    // trigger location permission dialog
    
    app.alerts.element.collectionViews.buttons["Allow"].tap()
    

    但是,Xcode 7(和 Xcode 7.1 Beta)会在成功解除警报后崩溃。我已经打开了bug report with Apple 并鼓励所有遇到问题的人复制它。

    【讨论】:

    • 现在我遇到了@Joe Masilotti 的问题。但我注意到它只发生在 iOS 启动的警报中。
    • 正确,@Salmo。您可以忽略自己的 UIAlertViews 和 UIAlertControllers 而不会出现问题。
    • 我刚刚找到了一个解决方法。我把它贴在下面。但我也会像你一样在 Apple 上开一期。
    【解决方案3】:

    xcode生成的unicode字符格式不对,是xcode的bug。作为临时解决方法,您可以替换

    [app.alerts[@"\U201cMyApp\U201d Would Like to Send You Notifications"].collectionViews.buttons[@"OK"] tap];
    

    [app.alerts[@"\u201cMyApp\u201d Would Like to Send You Notifications"].collectionViews.buttons[@"OK"] tap];
    

    \u

    上的所有 \U

    【讨论】:

      猜你喜欢
      • 2016-04-14
      • 1970-01-01
      • 1970-01-01
      • 2014-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      • 1970-01-01
      相关资源
      最近更新 更多