Simulating Text Entry into Views
Let us know how you feel about this
last updated: 2016-10
A common task for test is to enter text into views. UITest provides two API's to address this need:
Each of these will be discussed in more details below.
IApp.EnterText method allows a test to enter text into a view. The behaviour of this method is slightly different between iOS and Android:
- iOS – UITest will display the soft keyboard, and then simulate presses on the keyboard.
- Android – UITest does directly use the soft keyboard. Instead, the Xamarin Test Cloud Agent transparently injects itself between the soft keyboard and the application and simulates key presses.
The following snippet shows is an example of entering text:
app.EnterText(c=>c.Marked("creditCardTextField"), new string('9', 15));
Disable the Hardware Keyboard
IApp.EnterText will fail if the iOS simulator is configured to use the hardware keyboard. Before running your UITests locally, ensure that the simulator is configured to use the soft keyboard.
IApp.ClearText method will clear the text from the view, for example: