Simulating Basic Touch Actions Over Android Open Applications (Legacy)

Applies to TestComplete 15.0, last modified on November 17, 2021
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.

TestComplete provides various features you can use to simulate actions over your Android devices. This topic describes how to simulate basic touch actions over supported Android controls in Android Open Applications.

Basic Concepts

If your Android application is Open, it exposes its controls, methods and properties to TestComplete. For all objects in Android Open Applications, TestComplete provides a number of specific properties and methods that let you simulate user actions over the controls.

To simulate basic Touch and Long press touch actions over controls in your tested Android applications, you can use the Touch and LongTouch methods TestComplete adds to all tested Android objects. Both these methods have the parameters that specify the control-related coordinates of the point where the touch is to be simulated. If these parameters are omitted, the touch action is simulated at the center of the control.

You can also simulate Drag actions over controls. A Drag action has the parameters that let you specify the coordinates where the initial touch will be simulated, as well as the horizontal and vertical distance of the drag.

Depending on the control’s class TestComplete also provides a set of object-specific methods you can use to simulate various touch actions. For example, for Android GridView controls, TestComplete provides the TouchCell and LongTouchCell methods you can use to simulate touch actions over individual cells of the control. For detailed information on how to simulate various actions over supported controls, see appropriate topics in the Working With Android Controls section.

Simulating User Actions From Keyword Tests

To simulate touch actions over Android controls in keyword tests, call the Touch or LongTouch methods of the desired control with the needed parameters by using the On-Screen Action, Call Object Method, Run Code Snippet or Run Script Routine operations.

The image below demonstrates the On-Screen Action operation that calls the Touch method of the Android Button control to simulate a touch action at the point (10, 10) of the button:

Simulating touching a button

Simulating User Actions From Scripts

To simulate touch actions over controls in scripts, call the appropriate Touch or LongTouch methods of the object that corresponds to the tested control.

The sample script code below demonstrates how to simulate a touch action within the button control at the point (10, 10):

JavaScript, JScript

function Test()
{

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

  var p = Mobile.Device("MyDevice").Process("smartbear.example.orders");
  var button = p.RootLayout("").Layout("buttons_layout").Button("newButton");

  // Simualtes touching a button at the point (10, 10)
  button.Touch(10,10);

  // ...

}

Python

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

  p = Mobile.Device("MyDevice").Process("smartbear.example.orders");
  button = p.RootLayout("").Layout("buttons_layout").Button("newButton");

  # Simualtes touching a button at the point (10, 10)
  button.Touch(10,10);

VBScript

Sub Test

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

  Set p = Mobile.Device("MyDevice").Process("smartbear.example.orders")
  Set button = p.RootLayout("").Layout("buttons_layout").Button("newButton")

  ' Simualtes touching a button at the point (10, 10)
  Call button.Touch(10,10)

  …

End Sub

DelphiScript

procedure Test();
var p, button;
begin

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

  p := Mobile.Device('MyDevice').Process('smartbear.example.orders');
  button := p.RootLayout('').Layout('buttons_layout').Button('newButton');

  // Simualtes touching a button at the point (10, 10)
  button.Touch(10,10);

  …

end;

C++Script, C#Script

function Test()
{

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

  var p = Mobile["Device"]("MyDevice")["Process"]("smartbear.example.orders");
  var button = p["RootLayout"]("")["Layout"]("buttons_layout")["Button"]("newButton");

  // Simualtes touching a button at the point (10, 10)
  button["Touch"](10,10);

  …

}

See Also

Simulating Basic Touch Actions Over Android Devices (Legacy)
Recording Gestures (Multi-Touch Events) (Legacy)
Simulating Basic User Actions in Image-Based Tests

Highlight search results