SetOrientation Method

Applies to TestComplete 15.63, last modified on April 10, 2024
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 SetOrientation method sets the orientation of a mobile device’s screen.

Declaration

ProgObj.SetOrientation(Value)

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

Applies To

The method is applied to the following objects:

Parameters

The method has the following parameter:

Value

One of the following constants:

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

These constants are defined in the ScreenOrientation object, but you can omit the object name. So you can use just soPortrait instead of ScreenOrientation.soPortrait.

Result Value

True if the orientation was changes successfully; False otherwise.

Remarks

For information on specifics of using the SetOrientation method on Android and iOS applications, see Simulating Screen Rotation - Specifics and Possible Issues.

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

Simulating Screen Rotation (Legacy)
Testing Android Applications (Legacy)
Testing iOS Applications (Legacy)
AndroidDesktop Object
ResetOrientation Method
GetOrientation Method

Highlight search results