带有 unicode 的字符串在新 XCode UI 测试中不匹配,测试失败

String with unicode doesn't match on new XCode UI Test and the test fails

我正在使用新的 XCode 进行一些 UI 测试 7. 我的应用程序如何使用通知,在第一次使用时 iOS 自动询问 '"MyApp" Would Like to向您发送通知'。

当我记录测试时,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 在 MyApp 名称上放置了 unicode 而不是引号信号。 当 运行 时,测试失败并出现错误 "No matches found for alert"。

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

清楚了吗? 有人遇到过同样的问题吗?

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

1- XCode

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

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

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

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 并鼓励所有遇到问题的人复制它。

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

我改变了这一行

[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];
}

我做了两处修改

  • unicodes上的四个0000是为了避免构建失败
  • 并且在点击警报之前进行验证以避免测试失败

xcode生成的unicode字符格式错误所以是xcodebug。作为临时解决方法,您可以替换

[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