How to get a link to TextField in user interface tests in Xcode 7

I am trying to use user interface tests in the beta version of xcode 7. I have a storyboard with two text fields. Both text fields have outputs and different recovery identifiers. I wrote a test, but the generated code is pretty unreadable and it doesn't work:

app.otherElements.containingType(.TextField, identifier:"y").childrenMatchingType(.TextField).elementBoundByIndex(0).typeText("hello") 

I also tried the following and will work based on the text of Placeholder?!?

 app.textFields["PlaceholderText"].typeText("hello") 

What is the correct way to get a link to TextField in user interface tests?

+6
source share
1 answer

You need to set the accessibility identifier in the storyboard for this particular text field. Check out the image below:

enter image description here

So, you can request textField with an accessibility identifier as follows:

 let app = XCUIApplication() app.launch() let nameTextField = app.textFields["nameTextField"] nameTextField.tap() nameTextField.typeText("Hello John") 
+21
source

All Articles