I am getting a following error message during the UI tests when I test it with `onNodeWithText` , bu...
k
I am getting a following error message during the UI tests when I test it with
onNodeWithText
, but I'm not sure what's causing 2 nodes to be found. đź§µ
Copy code
java.lang.AssertionError: Failed to perform text input.
Reason: Expected exactly '1' node but found '2' nodes that satisfy: (Text + EditableText contains 'Username' (ignoreCase: false))
Nodes found:
1) Node #123 at (l=42.0, t=350.0, r=1398.0, b=574.0)px, Tag: 'Username'
Focused = 'false'
ImeAction = 'Done'
EditableText = '+'
TextSelectionRange = 'TextRange(1, 1)'
Text = '[Username]'
Actions = [RequestFocus, GetTextLayoutResult, SetText, SetSelection, OnClick, OnLongClick, PasteText]
MergeDescendants = 'true'
Has 1 sibling
2) Node #111 at (l=196.0, t=144.0, r=709.0, b=247.0)px
Text = '[Username]'
Actions = [GetTextLayoutResult]
Has 2 siblings
It does work if I use testTag , but is it possible to handle this without testTag?
s
Well it seems like there are two nodes which have the “Username” text in them, as the error tells you, and
onNodeWithText()
can’t handle that by itself since it can’t know which one to pick.
k
Yep, but is it possible to tell the Compose that I want just an
OutlineTextField
one?
s
Not that I'm aware of. The node matching system has a set of things it can match on, some semantics, and which TextField you use isn't one of them. What I'd do in most cases is have a testTag, but it really depends how your entire UI looks like. Maybe there's even a way to find a list of matching itmes and get the one you need with an index? But that feels worse that testTag imo
k
Yeah. Thanks. I might just use
testTag
1885 Views