XCUITest 如何让标签比较不区分大小写?

How to make label comparison case insensitive in XCUITest?

在工作中,我们有几个依赖于标签的测试。遗憾的是,标签区分大小写,因此 "Attachment" 与 "attachment" 不同。有没有办法配置 XCUI 进行不区分大小写的标签比较?

我希望存在 continueAfterFailure 这样的东西。

我尝试在网上和 Whosebug (uppercase, lowercase, case and case sensitive) 中查找,但没有找到有用的信息。我知道最好的解决方案是创建 AX id 并且也会为此努力,但我想知道是否可以进行不区分大小写的标签比较。

感谢任何指点。谢谢!

您可以组成一个 NSPredicate 来进行不区分大小写的字符串匹配,例如

extension XCUIElementQuery {
    func caseInsensitiveLabel(_ label: String) -> XCUIElement {
        return self.matching(NSPredicate(format: "label MATCHES[cd] %@", label)).firstMatch
    }
}

let app = XCUIApplication()
let label = app.staticTexts.caseInsensitiveLabel("sOmE tExT")
XCAssert(label.exists)