Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions devices/wda/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func filterSourceElements(source sourceTreeElement) []types.ScreenElement {
childElements = append(childElements, filterSourceElements(child)...)
}

acceptedTypes := []string{"TextField", "Button", "Switch", "Icon", "SearchField", "StaticText", "Image", "SecureTextField", "WebView"}
acceptedTypes := []string{"TextField", "TextView", "Button", "Switch", "Icon", "SearchField", "StaticText", "Image", "SecureTextField", "WebView"}

// strip XCUIElementType prefix if present
elementType := strings.TrimPrefix(source.Type, "XCUIElementType")
Expand All @@ -60,7 +60,7 @@ func filterSourceElements(source sourceTreeElement) []types.ScreenElement {
}

hasIdentifier := source.Label != nil || source.Name != nil || source.RawIdentifier != nil || source.PlaceholderValue != nil
alwaysInclude := elementType == "TextField" || elementType == "SecureTextField" || elementType == "Button" || elementType == "Switch" || elementType == "SearchField" || elementType == "WebView"
alwaysInclude := elementType == "TextField" || elementType == "TextView" || elementType == "SecureTextField" || elementType == "Button" || elementType == "Switch" || elementType == "SearchField" || elementType == "WebView"
if !hasIdentifier && !alwaysInclude {
return childElements
}
Expand Down
41 changes: 41 additions & 0 deletions devices/wda/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,47 @@ func TestFilterSourceElementsKeepsNestedWebViewsWithDifferentRects(t *testing.T)
}
}

func TestFilterSourceElementsIncludesMultilineTextView(t *testing.T) {
// A multiline React Native TextInput renders as a UITextView
// (XCUIElementTypeTextView). It must appear in the dump so it can be
// located and filled, just like a single-line TextField.
tree := sourceTreeElement{
Type: "XCUIElementTypeOther",
Rect: visibleRect(0, 0, 402, 874),
Children: []sourceTreeElement{
{
Type: "XCUIElementTypeTextView",
Label: strPtr("Notes"),
Rect: visibleRect(24, 200, 354, 120),
},
},
}

output := filterSourceElements(tree)

if len(output) != 1 {
t.Fatalf("expected 1 top-level element (TextView), got %d: %+v", len(output), output)
}

textView := output[0]
if textView.Type != "TextView" || elementLabel(textView) != "Notes" {
t.Errorf("expected a TextView labeled 'Notes', got %+v", textView)
}
}

func TestFilterSourceElementsIncludesTextViewWithoutIdentifier(t *testing.T) {
// An auto-focused multiline input may carry no label/name yet still needs
// to be present in the tree, so TextView is always included like TextField.
output := filterSourceElements(sourceTreeElement{
Type: "XCUIElementTypeTextView",
Rect: visibleRect(24, 200, 354, 120),
})

if len(output) != 1 || output[0].Type != "TextView" {
t.Fatalf("expected an unlabeled TextView to be included, got %+v", output)
}
}

func TestFilterSourceElementsOmitsChildrenFromJsonWhenEmpty(t *testing.T) {
// Leaf elements must not serialize an empty "children" array, so the
// JSON output stays unchanged for consumers that expect leaves.
Expand Down
Loading