我正在使用Xcode8.3.3并编写一个XCUI测试。
我有以下资料:
let address = XCUIApplication().buttons["URL"].value as! String
在调试器中,我可以看到值是:
ios - Swift XCUI字符串声明失败-LMLPHP
如果我设置
expectedURL = "\u{e2}auth.int....net"然后返回:ios - Swift XCUI字符串声明失败-LMLPHP
如果我设置
expectedURL = "auth.int....net"然后返回:ios - Swift XCUI字符串声明失败-LMLPHP
如何使测试断言找到两个相等的字符串?
尝试了以下操作,但没有替换“\u{e2}”:

let address = value.components(separatedBy: ",").first!.replacingOccurrences(of: "\u{e2}", with: "")

而且(但它不能替换“\u{e2}”):
let range = Range<String.Index>(uncheckedBounds: (lower: address.startIndex, upper: address.endIndex))
let strippedAddress = address.replacingOccurrences(of:"\\u{e2}", with: "", options: .literal, range: range)

对于断言,我使用XCTAssertEqual(address, expectedURL)

最佳答案

您可以通过用字母数字字符分隔,然后用空字符串连接来修复它,如下所示。

let myString = address.components(separatedBy: CharacterSet.alphanumerics.inverted).joined(separator: "")

myString则等于authintxxxxxxxnet(没有“.”字符),因此您应该能够将预期的URL更改为匹配。
希望能有帮助!

关于ios - Swift XCUI字符串声明失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44955383/

10-14 22:17
查看更多