In testing compose `TextField` is there a way to s...
# compose-android
a
In testing compose
TextField
is there a way to simulate the keyboard backspace button while testing using
androidx.compose.ui.test
?
z
Focus the field and use performKeyInput to send a backspace key.
a
Thanks it worked
final solution is as follows(this is working in both commonTest and androidInstrumentaionTest)
Copy code
// moving cursor to the end
onNode(hasSetTextAction()).requestFocus().performTextInputSelection(TextRange(3, 3))
onNode(hasSetTextAction()).performKeyInput { pressKey(Key.Backspace) }
is there a more concise way to do this? Also, I saw one more API
performKeyPress
Copy code
onNode(hasSetTextAction().performKeyPress(KeyEvent(???))
But I couldn’t figure out what to pass
???
while writing the test in commonTest
z
I think keycodes might be platform-specific, so you'd probably have to define a common val to get the platform-specific backspace one
thank you color 1