Sensor Property

Applies to TestComplete 15.47, last modified on January 20, 2023
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.

Description

Provides access to a particular built-in sensor of the mobile device and to its measurements.

To determine the total number of built-in sensors that are available on the device, see the SensorsCount property.

Declaration

iOSDeviceObj.Sensor(Index)

Read-Only Property An iOSSensor object
iOSDeviceObj An expression, variable or parameter that specifies a reference to an iOSDevice object
Index [in]    Required    Integer    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

Index

The index of the desired built-in sensor. The index ranges from 0 to SensorsCount - 1.

Use one of the following values to get the sensor you want:

Index Sensor name
0 Accelerometer
1 Gyroscope
2 Magnetometer
3 Attitude

Property Value

The iOSSensor object that provides information about the specified sensor and its measurements.

Remarks

If the connected mobile device does not have a sensor with the specified index, an error occurs.

Example

The script below lists the names of all the sensors available on the connected iOS device:

JavaScript, JScript

function ListSensors()
{
  Mobile.SetCurrent("iPad John Smith");

  for (var i = 0; i < Mobile.Device().SensorsCount; i++)
  {
    Log.Message(Mobile.Device().Sensor(i).Name);
  }
}

Python

def ListSensors():
  Mobile.SetCurrent("iPad John Smith")

  for i in range (0, Mobile.Device().SensorsCount - 1):
    Log.Message(Mobile.Device().Sensor(i).Name)

VBScript

Sub ListSensors
  Dim i
  Call Mobile.SetCurrent("iPad John Smith")
  
  For i = 0 To Mobile.Device.SensorsCount - 1
    Call Log.Message(Mobile.Device.Sensor(i).Name)
  Next
End Sub

DelphiScript

procedure ListSensors;
var i;
begin
  Mobile.SetCurrent('iPad John Smith');

  for i := 0 to Mobile.Device.SensorsCount - 1 do 
  begin
    Log.Message(Mobile.Device.Sensor(i).Name);
  end;
end;

C++Script, C#Script

function ListSensors()
{
  Mobile["SetCurrent"]("iPad John Smith");

  for (var i = 0; i < Mobile["Device"]["SensorsCount"]; i++)
  {
    Log["Message"](Mobile["Device"]["Sensor"](i)["Name"]);
  }
}

See Also

Getting Data From Mobile Device Sensors (Legacy)
SensorsCount Property
iOSSensor Object
iOSDevice Object

Highlight search results