You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
struct BorderedTextField: View {
/// Placeholder localize string key
private var placeholder: LocalizedStringKey
/// Text binding.
@Binding
private var textBind: String
@Binding
private var errorTextBind: String?
/// Initialize a textfield with bordered pattern
/// - Parameters:
/// - placeholder: Localized Key for Placeholder.
/// - textBind: Text binding
init(placeholder: LocalizedStringKey,
textBind: Binding<String>,
errorTextBind: Binding<String?>? = nil) {
self.id = id
self.placeholder = placeholder
self._textBind = textBind
self._errorTextBind = errorTextBind ?? Binding<String?>.constant(nil)
}
var body: some View {
VStack(alignment: .leading) {
TextField(placeholder, text: $textBind)
.padding()
.overlay(
RoundedRectangle(cornerRadius: 8.0)
.stroke()
)
.accessibilityIdentifier("borderedtextfield.textfield")
Text(errorTextBind ?? "")
.foregroundColor(Color.red)
.accessibilityIdentifier("borderedtextfield.errortext")
}
.accessibilityElement(children: .contain)
}
}
I used accessibilityElement to retain all the child accessibilityIdentifier so I can differentiate them by their parents. Thus a ViewHierarchy structure is important.
Expectation
I hope that the View Hierarchy on EarlGrey is shown like what XCUIApplication does.
I thought my current accessibilityIdentifier structure using accessibilityElement can work on UITest. But I was wrong when I'm using EarlGrey.
The Issue
After taking sometime looking at the View Hierarchy I discover this.
All UIViewControllerRepresentable and UIViewRepresentable somewhat being put outside of the View Hierarchy. This will eliminate my chance on using the parent identifier to get a certain component.
I checked with a UIViewControllerRepresentable and a UIButton wrapped inside UIViewRepresentable. It will put the View outside of the view hierarchy.
And yes. I'm surprised, underneath Apple still use UIViewRepresentable on UITextField for SwiftUI TextField haha.
Any help is really appreciated. Thank you!
The text was updated successfully, but these errors were encountered:
Background
Hi there! I'm a beginner and still learning about EarlGrey and how to use them.
I created a simple SwiftUI View as simple as this. And want to test them.
Here's the SwiftUI Code
Here's the BorderedTextField
I used
accessibilityElement
to retain all the childaccessibilityIdentifier
so I can differentiate them by theirparents
. Thus a ViewHierarchy structure is important.Expectation
I hope that the View Hierarchy on EarlGrey is shown like what XCUIApplication does.
I thought my current accessibilityIdentifier structure using accessibilityElement can work on UITest. But I was wrong when I'm using EarlGrey.
The Issue
After taking sometime looking at the View Hierarchy I discover this.
All
UIViewControllerRepresentable
andUIViewRepresentable
somewhat being put outside of the View Hierarchy. This will eliminate my chance on using theparent
identifier to get a certain component.I checked with a
UIViewControllerRepresentable
and aUIButton
wrapped insideUIViewRepresentable
. It will put the View outside of the view hierarchy.Any help is really appreciated. Thank you!
The text was updated successfully, but these errors were encountered: