0
votes

I'm trying to create a UITest using the recording function for an app that contains multiple UITextFields per view. When trying to do so I'm having a couple issues.

To simplify the issue I have created an application with two text fields nested inside one subview as shown in the picture.

single view controller with two UITextFields in a subview

From here I opened the identity inspector and changed the label of the two UITextFields under the accessibility heading to 'topField' and 'bottomField' (accessibility disabled on the gray UIView). Then I went into the UITest 'testExample' function and click the record button. From here I click the top text field, type something in, then when I click the bottom text field I get this error 'Timestamped Event Matching Error: Failed to find matching element'.

Xcode pop up alert

What am I missing here? I know this is a result of Xcode not being able to find the text field in the hierarchy, but I don't know why since I have given labels to each element in accessibility. I am able to manually write the code into the testing method to access the second text field without any errors, but the recording is not working. Any help is greatly appreciated.

With which framework are you writing your tests, XCUITest?Brandon Minnick
I believe I am. I figured out the issue. It was that even though I had accessibility checked off in the identity inspector I had to add a runtime attribute of 'isAccessibilityElement' and set it to true in order for the errors not to happen. I'm not sure why this is the case, but it worked and allowed me to record the test.Codex