Home > Mobile >  Can a staticText be detected if its label which is variable contains "curly quotes"?
Can a staticText be detected if its label which is variable contains "curly quotes"?

Time:12-10

I need to assert the existence of a generated staticText on the screen. The staticText's label is the result of:

  1. An input text done by the user (variable!)
  2. Curly quotes that have been added at beginning and end by the app.

So if user inputs "abc" the staticText label will be “abc”. So I need to assert on a variable and not on a fixed string.

func test() throws {

//This part of the code I use to simulate the input.

let searchTerm = "abc"

app.typeText(searchTerm)

//This assert works but the input is variable so I need the assert to be based on a variable  
XCTAssertTrue(app.staticTexts\["“abc”"\].exists)

//So I build this string in order to search for this staticText

let staticTextLabel = "”\(searchTerm)”"

This assert fails indicating the staticText is not present

XCTAssertTrue(app.staticTexts\[staticTextLabel\].exists)

//This works normally if the label I am looking for does not contain curly quotes!

}

By breakpointing and executing this on the debug console I get:

po app.staticTexts --> StaticText, 0x7ff12af25b50, {...}, label: '“abc”'

po staticTextLabel --> "”abc”"

po app.staticTexts["“abc”"].exists --> True

po app.staticTexts[staticTextLabel].exists --> False

Can you assess on what I may be missing here? The assert works on other variable staticTexts that do not contain these curly quotes ”

enter image description here This is how the staticText is displayed in the app. In this case the search was not for abc but what is causing the issue is the closing curly quotes!

CodePudding user response:

Your strings don't match.

staticTextLabel uses ”abc”, while app.staticTexts["“abc”"] uses “abc”.

If you put both of these into a diff tool you'll see the opening quote is not the same. The variable is a right double quote and the element is returning a left double quote. You can visually see the subtle difference by looking at the weights of the top and bottom of the character.

  • Related