Swift XCUI string assertion failing

£可爱£侵袭症+ 提交于 2020-01-06 06:09:32

问题


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: "")

myStringis 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!