I am looking for a text given in parameter in my textviews. I am sure that it exists because I see it on the screen, but somehow comparing them fails.
Here is a method:
func checkText(_ text: String) {
for tv in app.textViews.allElementsBoundByIndex {
if let typedText = tv.value as? String {
print(typedText)
print(text)
print(typedText == text)
}
}
}
CONSOLE OUPUT:
This is a test.
This is a test.
false
I dont know how this is possible.
I have also tried this way:
if myTextView.exists {
if let typedText = myTextView.value as? String {
XCTAssertEqual(typedText, text, "The texts are not matching")
}
}
But it gives an error saying that the texts are not matching, because "This is a test." is not equal to "This is a test."
3
Answers
As guys wrote in the comments, my textview was adding "Object Replacement Character" or "U+FFFC" after it finished editing.
To make the strings equal, I needed to do this:
So this will now succeed:
your function seems to work correctly, the "." are not the same between the two texts (check on https://www.diffchecker.com/diff )
When I convert your last 3 bytes which is
[239, 191, 188]
, With usingThe output is :
That means indicates that the last character of one of these strings represents an extra space character
Maybe you are adding to unwanted space to text or in your
XCUIElement
value adds it . Thats why equalization operation returns false