PressButton Method

Applies to TestComplete 14.70, last modified on April 22, 2021

Description

Simulates pressing a device key.

Simulation of pressing physical buttons on iOS devices is currently not supported. However, you can use the method to simulate pressing keys on the physical keyboard connected to your iOS device.

Declaration

ProgObj.PressButton(KeyPressType)

ProgObj An expression, variable or parameter that specifies a reference to one of the objects listed in the Applies To section
Key [in]    Required    MobileButtonKey    
PressType [in]    Optional    Integer Default value: aptDownUp   
Result None

Applies To

The method is applied to the following objects:

Parameters

The method has the following parameters:

Key

The key to be pressed. For a list of possible values, see Mobile Key Constants.

Note: Currently, only the following key constants are supported for iOS devices:

Supported Key Constants

PressType

One of the following constants that specify the type of the key event:

Constant Value Description
aptDown 1 Simulate pressing a key.
aptUp 2 Simulate releasing a key.
aptDownUp 4 (Default.) Simulate pressing and releasing a key, one after another.

Result Value

None.

Remarks

This method is asynchronous. This means that TestComplete continues running the test, no matter whether it has finished or not. For information on how it may affect testing on Android devices, see Possible Issues.

To record this method, press the appropriate emulated button in the Mobile Screen window of TestComplete.

Example

The example below demonstrates how to use the PressButton method to simulate pressing a physical button on a mobile device:

JavaScript, JScript

function Test()
{
  // Specify the current device
  Mobile.SetCurrent("MyDevice");

  // Simulate user actions
  …
  Mobile.Device().PressButton(mbkZoomIn, aptDownUp);
  …

}

Python

def Test():
  # Specify the current device
  Mobile.SetCurrent("MyDevice")

  # Simulate user actions
  # ...
  Mobile.Device().PressButton(mbkZoomIn, aptDownUp)
  # ...

VBScript

Sub Test

  ' Specify the current device
  Call Mobile.SetCurrent("MyDevice")

  ' Simulate user actions
  …
  Call Mobile.Device.PressButton(mbkZoomIn, aptDownUp)
  …

End Sub

DelphiScript

procedure Test;
begin
  // Specify the current device
  Mobile.SetCurrent('MyDevice');

  // Simulate user actions
  …
  Mobile.Device.PressButton(mbkZoomIn, aptDownUp);
  …

end;

C++Script, C#Script

function Test()
{
  // Specify the current device
  Mobile["SetCurrent"]("MyDevice");

  // Simulate user actions
  …
  Mobile["Device"]["PressButton"](mbkZoomIn, aptDownUp);
  …

}

See Also

Testing Android Applications
AndroidDevice Object
iOSDevice Object
Mobile Key Constants
Simulating Physical Button Events

Highlight search results