GetOrientation Method

Applies to TestComplete 15.45, last modified on December 01, 2022
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

The Mobile.Device.Desktop.GetOrientation method gets the current orientation of a mobile devices desktop.

Declaration

ProgObj.GetOrientation()

ProgObj An expression, variable or parameter that specifies a reference to one of the objects listed in the Applies To section
Result Integer

Applies To

The method is applied to the following objects:

Result Value

The number specifying current orientation of a mobile devices screen. The following values are possible:

Value Constant Description
0 soPortrait Portrait orientation.
1 soLandscapeLeft Left (normal) landscape orientation.
2 soPortraitUpsideDown Upside down (reverse) portrait orientation.
3 soLandscapeRight Right (reverse) landscape orientation.

Example

The following example checks if the device is in portrait orientation and, if it is not, sets the orientation to portrait.

JavaScript, JScript

function Test()
{
  Mobile.SetCurrent("MyDevice");

  var Desktop = Mobile.Device().Desktop;
  var Orientation = Desktop.GetOrientation();
  
  if (Orientation != soPortrait)
    Desktop.SetOrientation(soPortrait);
}

Python

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

  Desktop = Mobile.Device().Desktop 
  Orientation = Desktop.GetOrientation()
  
  if (Orientation != soPortrait):
    Desktop.SetOrientation(soPortrait)

VBScript

Sub Test()
  Dim Desktop, Orientation

  Mobile.SetCurrent("MyDevice")

  Set Desktop = Mobile.Device.Desktop
  Orientation = Desktop.GetOrientation()
  
  If Not Orientation = soPortrait Then
    Desktop.SetOrientation(soPortrait)
  End If
End Sub

DelphiScript

procedure Test();
var
  Desktop, Orientation;
begin
  Mobile.SetCurrent('MyDevice');

  Desktop := Mobile.Device.Desktop;
  Orientation := Desktop.GetOrientation();
  
  if not Orientation = soPortrait then
    Desktop.SetOrientation(soPortrait);
end;

C++Script, C#Script

function Test()
{
  Mobile["SetCurrent"]("MyDevice");

  var Desktop = Mobile["Device"].Desktop;
  var Orientation = Desktop["GetOrientation"]();
  
  if (Orientation != soPortrait)
    Desktop["SetOrientation"](soPortrait);
}

See Also

Testing Android Applications (Legacy)
Testing iOS Applications (Legacy)
SetOrientation Method
ResetOrientation Method

Highlight search results