Simulating Text Input in Android Open Applications (Legacy)

Applies to TestComplete 15.20, last modified on January 19, 2022
The information below concerns legacy mobile tests that work with mobile devices connected to the local computer. For new mobile tests, we recommend using the newer cloud-compatible approach.

In your tests you often need to simulate text input - a sequence of keystrokes sent to the specified object. This topic describes how to simulate keystrokes being sent to controls in Android Open Applications.

Basic Concepts

To simulate text input in your tests you can do any of the following:

  • Use the Keys method - TestComplete adds this method to all objects in Android Open Applications. The method takes the string of keys to be sent and sends it to the object.

  • Use specific methods and properties - Depending on the control’s class TestComplete can provide a number of methods and properties you can use to simulate specific user actions over the control. For example, for Android TextEdit controls, TestComplete provides the SetText method. The method sets the textual content of the appropriate control. For detailed information on how to use these specific properties and methods to simulate text input, see appropriate topics in the Working With Android Controls section.

  • Use native properties and methods of tested Android controls - TestComplete provides access to public, protected and private methods and properties of controls in your tested Android applications. You can use them to simulate text input.

For information on how to simulate input of local (national) characters in your tests, see Simulating Local Symbol Input (Legacy).

Simulating Text Input in Keyword Tests

To simulate text input in keyword tests, call the desired method of the control by using the On-Screen Action, Call Object Method, Run Code Snippet or Run Script Routine operations.

For example, the image below demonstrates the On-Screen Action operation that calls the keys method of the Android EditText control to simulate text input:

Simulating text input in a keyword test

Simulating Text Input in Scripts

To simulate text input in scripts, call the appropriate methods of the desired control. For example, the sample script below demonstrates how to simulate text input in an Android EditText control:

JavaScript, JScript

function Test()
{

  Mobile.SetCurrent("MyDevice");
  // ...

  var p = Mobile.Device("MyDevice").Process("smartbear.example.orders");
  var editText = p.RootLayout("").ScrollView("NO_ID").EditText("cust_name");

  // Simulates text input
  editText.Keys("John Smith");

  // ...

}

Python

def Test():
  Mobile.SetCurrent("MyDevice");
  # ...

  p = Mobile.Device("MyDevice").Process("smartbear.example.orders");
  editText = p.RootLayout("").ScrollView("NO_ID").EditText("cust_name");

  # Simulates text input
  editText.Keys("John Smith");

  # ...

VBScript

Sub Test

  Mobile.SetCurrent("MyDevice")
  ' ...

  Set p = Mobile.Device("MyDevice").Process("smartbear.example.orders")
  Set editText = p.RootLayout("").ScrollView("NO_ID").EditText("cust_name")

  ' Simulates text input
  editText.Keys("John Smith")

  ' ...

End Sub

DelphiScript

procedure Test();
var p, editText;
begin

  Mobile.SetCurrent('MyDevice');
  // ...

  p := Mobile.Device('MyDevice').Process('smartbear.example.orders');
  editText := p.RootLayout('').ScrollView('NO_ID').EditText('cust_name');

  // Simulates text input
  editText.Keys('John Smith');

  // ...

end;

C++Script, C#Script

function Test()
{

  Mobile["SetCurrent"]("MyDevice");
  // ...

  var p = Mobile["Device"]("MyDevice")["Process"]("smartbear.example.orders");
  var editText = p["RootLayout"]("")["ScrollView"]("NO_ID")["EditText"]("cust_name");

  // Simulates text input
  editText["Keys"]("John Smith");

  // ...

}

See Also

Simulating Text Input on Android Devices (Legacy)
Simulating Local Symbol Input (Legacy)
Recording Text Input

Highlight search results