GetOrientation Method

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

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
Testing iOS Applications
SetOrientation Method
ResetOrientation Method

Highlight search results