Getting Device's Screen Resolution (Legacy)

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.

You can check the screen resolution of Android or iOS devices to run some operations only on large-screen or small-screen devices. To do this, use the Width and Height properties of the AndroidDesktop or iOSDesktop object. These properties return the width and height of the device's screen in pixels. Note that the width and height values are swapped when the device orientation changes (from portrait to landscape and vice versa).

Getting Device Resolution in Keyword Tests

In keyword tests, use the Call Object Method operation to get the Width and Height properties. To configure this operation:

  • Add the Call Object Method operation to your keyword test. TestComplete will show the Operation Parameters wizard.

  • Enter one of the following as the object name:

    • Aliases.device.Desktop - if you use Name Mapping,

    • Mobile.Device.Desktop - if you do not use Name Mapping,

    • Mobile.Device("DeviceName").Desktop - if you do not use Name Mapping and the device is not the current one.

    Click Next.

  • Select Height [Get] or Width [Get] from the property list and click Finish.

Right after the Call Object Method operation, add an operation that will use the width or height value. For example, the Log Message operation that will post the Last Operation Result value to the test log, or the Set Variable Value operation that will save the value to a variable for later use.

Getting mobile device resolution from in keyword tests

Getting Device Resolution in Scripts

In scripts, you can get the width and height of the device's screen as shown in this example:

JavaScript, JScript

function Test()
{
  Mobile.SetCurrent("MyDevice");
  var Width = Mobile.Device().Desktop.Width;
  var Height = Mobile.Device().Desktop.Height;
  Log.Message("The screen resolution is " + Width + "x" + Height)
}

Python

def Test():
  Mobile.SetCurrent("MyDevice"); 
  Width = Mobile.Device().Desktop.Width;
  Height = Mobile.Device().Desktop.Height;
  Log.Message("The screen resolution is " + IntToStr(Width) + "x" + IntToStr(Height));

VBScript

Sub Test
  Dim Witdth, Height
  Call Mobile.SetCurrent("MyDevice")
  Width = Mobile.Device.Desktop.Width
  Height = Mobile.Device.Desktop.Height
  Call Log.Message("The screen resolution is " + VarToStr(Width) + "x" + VarToStr(Height))
End Sub

DelphiScript

procedure Test;
var Width, Height;
begin
  Mobile.SetCurrent('MyDevice');
  Width := Mobile.Device.Desktop.Width;
  Height := Mobile.Device.Desktop.Height;
  Log.Message('The screen resolution is ' + VarToStr(Width) + 'x' + VarToStr(Height));
end;

C++Script, C#Script

function Test()
{
  Mobile["SetCurrent"]("MyDevice")
  var Width = Mobile["Device"]["Desktop"]["Width"];
  var Height = Mobile["Device"]["Desktop"]["Height"];
  Log["Message"]("The screen resolution is " + Width + "x" + Height);
}

See Also

AndroidDesktop Object
iOSDesktop Object
Checking Device Screen Orientation (Legacy)

Highlight search results