Swift XCUI 字符串断言失败 [英] Swift XCUI string assertion failing

查看:35
本文介绍了Swift XCUI 字符串断言失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using xcode 8.3.3 and writing a XCUI test.

我有以下几点:let address = XCUIApplication().buttons["URL"].value as!字符串

在调试器中查看,可以看到值是:

Looking in the debugger, I can see the value is:

如果我设置expectedURL = "\u{e2}auth.int....net" 然后它返回:

If I set expectedURL = "\u{e2}auth.int....net" then it returns:

如果我设置expectedURL = "auth.int....net" 然后它返回:

If I set expectedURL = "auth.int....net" then it returns:

如何让测试断言发现两个字符串相等?

尝试了以下操作,但它没有替换\u{e2}":

Tried the following, but it doesn't replace the "\u{e2}":

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

还有(但它不会取代\u{e2}"):

And also (but it doesn't replace the "\u{e2}"):

let range = Range(uncheckedBounds: (lower: address.startIndex, upper: address.endIndex))

let strippedAddress = address.replacingOccurrences(of:"\\u{e2}", with: "", options: .literal, range: range)

对于断言,我使用 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 则等于 authintxxxxxxxxxnet(没有."字符),因此您应该能够更改预期的 URL 以匹配.

myStringis then equal to authintxxxxxxxxxnet (no "." characters), so you should just be able to change your expected URL to match.

希望有帮助!

这篇关于Swift XCUI 字符串断言失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆