Text Entry

Simulating Text Entry into Views

PDF for offline use
Related APIs:

Let us know how you feel about this

Translation Quality


0/250

last updated: 2016-10

A common task for test is to enter text into views. UITest provides two API's to address this need:

  • IApp.EnterText
  • IApp.ClearText

Each of these will be discussed in more details below.

Entering Text

The 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.

Clearing Text

The IApp.ClearText method will clear the text from the view, for example:

app.ClearText(c=>c.Marked("creditCardTextField"));

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.