繁体   English   中英

Swift XCUI字符串声明失败

[英]Swift XCUI string assertion failing

我正在使用xcode 8.3.3并编写XCUI测试。

我有以下内容: let address = XCUIApplication().buttons["URL"].value as! String let address = XCUIApplication().buttons["URL"].value as! String

在调试器中查看,我看到的值是:

在此处输入图片说明

如果我设置了expectedURL = "\\u{e2}auth.int....net"那么它将返回: 在此处输入图片说明

如果我设置了expectedURL = "auth.int....net"那么它将返回: 在此处输入图片说明

如何使测试断言找到两个字符串相等?

尝试了以下操作,但是它不能代替“ \\ 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等于authintxxxxxxxxxnet(没有“。”字符),因此您应该可以更改期望的URL以进行匹配。

希望有帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM