问题
I am using xcode 8.3.3 and writing a XCUI test.
I have the following:
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:
If I set
expectedURL = "auth.int....net"
then it returns:
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}":
let address = value.components(separatedBy: ",").first!.replacingOccurrences(of: "\u{e2}", with: "")
And also (but it doesn't replace the "\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)
回答1:
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.
Hope that helps!
来源:https://stackoverflow.com/questions/44955383/swift-xcui-string-assertion-failing