1

I'm developing my app with SwiftUI, but some elements are still from the UIKit world, e.g. one UITextField with special behavior, that's why I use a UIViewRepresentable where the makeUIView methods returns a UITextField.

When I try to enter text via UI test, I don't succeed in querying the textfield; even app.textFields doesn't return anything.

Is this because of using UIViewRepresentable, am I missing something?

swalkner
  • 16,679
  • 31
  • 123
  • 210
  • You need to make sure you have a coordinator and bindings setup to properly query and set values while using a UIViewRepresentable. It can get messy and often there are easier ways to do it besides using a UIViewRepresentable. Can I ask your reason for using it? Perhaps there's a different way. – xTwisteDx Apr 16 '21 at 18:34
  • the behavior of the app itself works correctly - I only don't know how to query it from within a UI test. I need to query the elements as that's a password field where I have to enter a value to continue in my UI test flow – swalkner Apr 16 '21 at 18:36
  • Meybe you should add a screenshot and app.debugDescription() result to this question – Roman Zakharov Apr 19 '21 at 07:39

1 Answers1

0

I had the same situation you described. Make sure to set accessibilityIdentifier in makeUIView. Also bear in mind that if you're setting isSecureTextEntry to true, you should access it using app.secureTextFields

Omer
  • 11
  • 2