LongTouch Method (ImageSetItem Object)

Applies to TestComplete 15.45, last modified on December 01, 2022

Description

Simulates a long touch over the control specified by its image in the Image Repository, or moves the control from one point to another.

Declaration

TestObj.LongTouch(StartX, StartY, EndX, EndY, SearchArea)

TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
StartX [in]    Optional    Integer Default value: -1   
StartY [in]    Optional    Integer Default value: -1   
EndX [in]    Optional    Integer Default value: -1   
EndY [in]    Optional    Integer Default value: -1   
SearchArea [in]    Optional    Object    
Result None

Applies To

View Mode

This method is available in the Object Browser panel and in other panels and dialogs in both Basic and Advanced view modes.

Parameters

The method has the following parameters:

StartX

Specifies the horizontal coordinate (in pixels) of the starting point of the long touch action (see Remarks).

StartY

Specifies the vertical coordinate (in pixels) of the starting point of the long touch action (see Remarks).

EndX

Specifies the horizontal coordinate (in pixels) of the ending point of the long touch action (see Remarks).

EndY

Specifies the vertical coordinate (in pixels) of the ending point of the long touch action (see Remarks).

SearchArea

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

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

If you use a desktop or web object as a parameter, the method will fail.

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 StartX and StartY coordinates are omitted, the action is simulated in the center of the control’s recognition area.

    If the EndX and EndY coordinates are omitted, a long touch is simulated at the point specified by the StartX and StartY coordinates.

  • If the StartX and StartY coordinates are specified, the method simulates a long touch event at the specified point of the control’s recognition area.
  • If all four coordinates are specified, the method starts a long touch event at point StartX, StartY and finishes it at point EndX, EndY. Typically this results in dragging the control from the starting point to the ending point.

Example

The following code locates the Calculator icon on the device screen and drags the icon from one point to another by simulating the long touch event:

JavaScript, JScript

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

  // Simulate long touch event over Calculator icon
  ImageRepository.launcher.TextView_Calculator.LongTouch(10, 10, 100, 100);
}

Python

def TestCalc():
  # Specify the current device
  Mobile.SetCurrent("MyAndroidDev", 0)
  # Simulate long touch event over Calculator icon
  ImageRepository.launcher.TextView_Calculator.LongTouch(10, 10, 100, 100)

VBScript

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

  ' Simulate long touch event over Calculator icon
  Call ImageRepository.launcher.TextView_Calculator.LongTouch(10, 10, 100, 100)
End Sub

DelphiScript

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

  // Simulate long touch event over Calculator icon
  ImageRepository.launcher.TextView_Calculator.LongTouch(10, 10, 100, 100);
end;

C++Script, C#Script

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

  // Simulate long touch event over Calculator icon
  ImageRepository["launcher"]["TextView_Calculator"]["Touch"](10, 10, 100, 100);
}

See Also

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

Highlight search results