[英]Swift XCUI string assertion failing
I am using xcode 8.3.3 and writing a XCUI test. 我正在使用xcode 8.3.3并编写XCUI测试。
I have the following: let address = XCUIApplication().buttons["URL"].value as! String
我有以下内容:
let address = XCUIApplication().buttons["URL"].value as! String
let address = XCUIApplication().buttons["URL"].value as! String
Looking in the debugger, I can see the value is: 在调试器中查看,我看到的值是:
If I set expectedURL = "\\u{e2}auth.int....net"
then it returns: 如果我设置了
expectedURL = "\\u{e2}auth.int....net"
那么它将返回:
If I set expectedURL = "auth.int....net"
then it returns: 如果我设置了
expectedURL = "auth.int....net"
那么它将返回:
How can I make the test assertion find the two strings to be equal? 如何使测试断言找到两个字符串相等?
Tried the following, but it doesn't replace the "\\u{e2}": 尝试了以下操作,但是它不能代替“ \\ u {e2}”:
let address = value.components(separatedBy: ",").first!.replacingOccurrences(of: "\u{e2}", with: "")
And also (but it doesn't replace the "\\u{e2}"): 并且(但它不能代替“ \\ 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)
For the assertion, I am using XCTAssertEqual(address, expectedURL)
对于断言,我正在使用
XCTAssertEqual(address, expectedURL)
You can fix it by separating by alphanumeric characters and then joining by an empty string, as shown below. 您可以通过以下方式解决此问题:用字母数字字符分隔,然后用空字符串连接,如下所示。
let myString = address.components(separatedBy: CharacterSet.alphanumerics.inverted).joined(separator: "")
myString
is then equal to authintxxxxxxxxxnet (no "." characters), so you should just be able to change your expected URL to match. 然后,
myString
等于authintxxxxxxxxxnet(没有“。”字符),因此您应该可以更改期望的URL以进行匹配。
Hope that helps! 希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.