gpt4 book ai didi

xcode - 在 XCode 7 中使用 unicode 字符进行的 UI XCTest 记录给出了错误的 Swift 代码

转载 作者:可可西里 更新时间:2023-10-31 23:44:23 27 4
gpt4 key购买 nike

现在,在我的应用程序上记录元素时,它会返回以下内容:

XCUIApplication().alerts["\U201cMy Application\U201d Would Like to Send You Notifications"].staticTexts["Notifications may include alerts, sounds, and icon badges. These can be configured in Settings."].tap()

这会引发编译器错误。然后我将其更改为这个,以遵循引用 unicode 字符的快速约定:

XCUIApplication().alerts["\u{201c}My Application\u{201d} Would Like to Send You Notifications"].staticTexts["Notifications may include alerts, sounds, and icon badges. These can be configured in Settings."].tap()

这确实编译通过了,但是测试失败了,因为 Swift 在测试时没有找到该元素。然后我尝试了这个:

XCUIApplication().alerts["“My Application” Would Like to Send You Notifications"].staticTexts["Notifications may include alerts, sounds, and icon badges. These can be configured in Settings."].tap()

结果相同

我意识到这可能是 xcode 的一个错误,但是有解决方法吗?这个问题似乎已经存在一段时间了。

最佳答案

我无法重现您的错误。使用 swift 约定 \u{201c} 效果很好。如果你想使用引号,你也可以尝试只使用反斜杠

"\"MyApp\" Would Like to Send You Notifications"

您的消息表明您想要对系统通知而不是您自己的 UIAlert 使用react。这就是为什么你找不到它。尝试在警报出现之前设置 UI 中断警报,然后对其使用react:

    addUIInterruptionMonitorWithDescription("\"MyApp\" Would Like to Send You Notifications") {
(alert) -> Bool in
alert.buttons["OK"].tap()
return true
}

另请考虑 Joe Masilotti 的出色 Cheat Sheet了解更多信息。

关于xcode - 在 XCode 7 中使用 unicode 字符进行的 UI XCTest 记录给出了错误的 Swift 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34167948/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com