'Referencing static string in Xcode UI test with apostrophe
In my project is a localized string in a *.strings file like this...
"some_key" = "Yada yada won't blah.\nBlah blah?";
In my UI Test, when I record the element and when I print object on the staticTexts dictionary, it's referenced with a string like this...
app.staticTexts["Yada yada won't blah.\nBlah blah?"]
However, in my test I localize the key and the string comes out with an extra escape character for the apostrophe in the contraction which I believe is breaking the label reference...
print("some_key".localized)
Yada yada won\'t blah.\nBlah blah?
I've tried replacing "\'" with "'" and even the below code...
let begin = id.substring(start: 0, offsetBy: 15)
let end = id.substring(start: 16, offsetBy: 41)
id = "\(begin ?? "")'\(end ?? "")"
...but the escape is always there.
How do I keep the break line, but remove the escape on the apostrophe?
I don't control the client code being tested, so I can't change how the text is setup and I can't reference with an accessibility identifier.
Solution 1:[1]
I believe you're looking for the replacingOccurrences(of:with:) function.
cleaned = id.replacingOccurences(of: "\'", with: "'")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mike Collins |
