Bradleycorn
11/19/2021, 7:40 PMTextField( value = myText,
onValueChanged = { new -> myText = new },
modifier = Modifier.testTag("MyInput"))
And I’m trying to set some text in the text field in a test:
composeTestRule.onNodeWithTag("MyInput").performTextInput("Test")
My test fails, and I get the error:
No input session started. Missing a focus?
What am I doing wrong here? Doing some digging into the testing source and debugging the nodes, it looks like the TextField
node doesn’t get focused for some reason. I tried adding a performClick()
before setting the text, but that didn’t help either. The node still has focused = false
… What am I missing?Laura Kelly
11/19/2021, 9:10 PMcomposeTestRule.onNode(hasSetTextAction()).performTextInput("Test")
work?Bradleycorn
11/19/2021, 9:40 PMJesse Hill
11/19/2021, 10:00 PMBradleycorn
11/19/2021, 10:04 PMMyForm
that rendered several `TextField`s and a Button
, like this:
TextField()
TextField()
TextField()
Button()
I was getting lucky that it was working in my app, because MyForm
was being called from a parent that had a `Column`:
@Composable fun MyScreen() {
Column {
Header()
MyForm()
Footer()
}
}
But to test MyForm
, it gets loaded on it’s own:
composeTestRule.setContent { MyForm() }
So in the test, all of those fields and the button are rendered on top of one another. In the end, the test can’t “focus” the first text field because it is underneath the button. 🤦
As soon as I put a Column
IN MyForm
, everything works like a champMyForm
back up piece by piece, I found my mistakeColton Idle
11/20/2021, 3:12 AM