Touch Method (ImageSetItem Object)

Applies to TestComplete 15.0, last modified on November 17, 2021

Description

Simulates a touch event over the control specified by its image in the Image Repository.

Declaration

ImageSetItem.Touch(X, Y, SearchArea)

ImageSetItem
X [in]    Optional    Integer Default value: 0   
Y [in]    Optional    Integer Default value: 0   
SearchArea [in]    Optional    Object    
Result None

Applies To

Parameters

The method has the following parameters:

X

Specifies the horizontal coordinate of the touch (see Remarks)

Y

Specifies the vertical coordinate of the touch (see Remarks).

SearchArea

Specifies the area, within which the method will search for the image. Can take the following values:

  • The screen of your Android or iOS device. Access the device by calling the Mobile.AndroidDevice.Desktop or Mobile.iOSDevice.Desktop property appropriately or by calling the Mobile.Device method.

  • A window or onscreen object in your mobile application.

  • Your current computer desktop (access it by calling the Sys object or the Sys.Desktop property), or a window or control in your desktop or web application. In this case, the method will simulate a click on the current computer desktop.

If the parameter is omitted, the method will search for the image on the screen of the current mobile device (you can set the current device by calling Mobile.SetCurrent in your script code, or the Select Device or Device Loop operation in your keyword test).

Result Value

None.

Remarks

  • The coordinates are specified relative to the top-left corner of the control’s recognition area marked with a red frame in the Preview box of the ImageSet editor.
  • The X and Y parameters of the method take the logical coordinates of the target point. Note that the logical coordinates (points) on iOS devices may not correspond to physical coordinates (pixels). For detailed information on logical and physical coordinates, see the iOS documentation.

    Typically, the scale factor for logical coordinates on high-resolution iOS devices is 2. So, in order to simulate a touch at the specified point of a control on an iOS device's screen, you need to specify the logical coordinates of the point, which are two times smaller than the point's physical coordinates.

  • If the X and Y coordinates are omitted, the touch is simulated in the center of the control’s recognition area marked with a red frame in the Preview box of the ImageSet editor.
  • Often, the Touch method is used without any parameters. So, it is recommended to specify the current device before calling the method. You can do this by calling Mobile.SetCurrent in script code, or by executing the Select Device operation in keyword tests.

Example

The following code gets access to the specified image set (calculator) and simulates touch events over the specified items of this image set:

JavaScript, JScript

function TestCalc()
{
  // Specify the current device
  Mobile.SetCurrent("MyAndroidDev", 0);

  // Run Calculator and simulate touches on its buttons
  ImageRepository.launcher.TextView_Calculator.Touch();
  var MySet = ImageRepository.calculator;
  MySet.Button_5.Touch();
  MySet.Button_Question1.Touch();
  MySet.Button_2.Touch();
  MySet.Button_Equal.Touch();
}

Python

def TestCalc():
  # Specify the current device
  Mobile.SetCurrent("MyAndroidDev", 0)
  # Run Calculator and simulate touches on its buttons
  ImageRepository.launcher.TextView_Calculator.Touch()
  MySet = ImageRepository.calculator
  MySet.Button_5.Touch()
  MySet.Button_Question1.Touch()
  MySet.Button_2.Touch()
  MySet.Button_Equal.Touch()

VBScript

Sub TestCalc
  ' Specify the current device
  Call Mobile.SetCurrent("MyAndroidDev", 0)

  ' Run Calculator and simulate touches on its buttons
  Call ImageRepository.launcher.TextView_Calculator.Touch
  Set MySet = ImageRepository.calculator
  Call MySet.Button_5.Touch
  Call MySet.Button_Question1.Touch
  Call MySet.Button_2.Touch
  Call MySet.Button_Equal.Touch
End Sub

DelphiScript

procedure TestCalc();
var MySet;
begin
  // Specify the current device
  Mobile.SetCurrent('MyAndroidDev', 0);

  // Run Calculator and simulate touches on its buttons
  ImageRepository.launcher.TextView_Calculator.Touch();
  MySet := ImageRepository.calculator;
  MySet.Button_5.Touch();
  MySet.Button_Question1.Touch();
  MySet.Button_2.Touch();
  MySet.Button_Equal.Touch();
end;

C++Script, C#Script

function TestCalc()
{
  // Specify the current device
  Mobile["SetCurrent"]("MyAndroidDev", 0);

  // Run Calculator and simulate touches on its buttons
  ImageRepository["launcher"]["TextView_Calculator"]["Touch"]();
  var MySet = ImageRepository["calculator"];
  MySet.Button_5["Touch"]();
  MySet.Button_Question1["Touch"]();
  MySet.Button_2["Touch"]();
  MySet.Button_Equal["Touch"]();
}

See Also

Testing Android Applications (Legacy)
ImageSetItem Object
LongTouch Method (ImageSetItem Object)
Image-Based Testing

Highlight search results