ScreenWidth Property

Applies to TestComplete 14.10, last modified on June 5, 2019

Description

The ScreenWidth property returns the screen width (in CSS pixels) defined for a mobile browser profile. Browser profiles are configured in the project’s Virtual Browsers properties; the browser screen width is specified in the Screen width column.

Declaration

VirtualBrowserInfoObj.ScreenWidth

Read-Only Property Integer
VirtualBrowserInfoObj An expression, variable or parameter that specifies a reference to a VirtualBrowserInfo object

Applies To

The property is applied to the following object:

Property Value

The browser screen width in CSS pixels.

Remarks

The browser screen size of a mobile device is not necessarily the same as the device’s physical screen resolution.

For example, Apple devices with Retina displays have double pixel density and show 1 CSS pixel using 4 physical pixels (2×2). While iPhone 5’s physical resolution is 1136×640, its browser screen size is 568×320 CSS pixels.

For information about specifying screen sizes for the mobile browser emulator, see Creating Mobile Browser Profiles.

Example

The following code checks the screen orientation of a mobile browser.

JavaScript, JScript

function Test()
{
  var browserInfo = VirtualBrowsers.Item("Apple iPad");

  if (browserInfo.ScreenHeight > browserInfo.ScreenWidth)
    Log.Message("The 'Apple iPad' emulator has portrait orientation.")
  else
    Log.Message("The 'Apple iPad' emulator has landscape orientation.");
}

Python

def Test():
  browserInfo = VirtualBrowsers.Item["Apple iPad"]

  if browserInfo.ScreenHeight > browserInfo.ScreenWidth:
    Log.Message("The 'Apple iPad' emulator has portrait orientation.")
  else:
    Log.Message("The 'Apple iPad' emulator has landscape orientation.")

VBScript

Sub Test
  Dim browserInfo
  Set browserInfo = VirtualBrowsers.Item("Apple iPad")

  If browserInfo.ScreenHeight > browserInfo.ScreenWidth Then
    Call Log.Message("The 'Apple iPad' emulator has portrait orientation.")
  Else
    Call Log.Message("The 'Apple iPad' emulator has landscape orientation.")
  End If
End Sub

DelphiScript

procedure Test;
var browserInfo;
begin
  browserInfo := VirtualBrowsers.Item('Apple iPad');

  if browserInfo.ScreenHeight > browserInfo.ScreenWidth then
    Log.Message('The "Apple iPad" emulator has portrait orientation.')
  else
    Log.Message('The "Apple iPad" emulator has landscape orientation.');
end;

C++Script, C#Script

function Test()
{
  var browserInfo = VirtualBrowsers["Item"]("Apple iPad");

  if (browserInfo["ScreenHeight"] > browserInfo["ScreenWidth"])
    Log["Message"]("The 'Apple iPad' emulator has portrait orientation.")
  else
    Log["Message"]("The 'Apple iPad' emulator has landscape orientation.");
}

See Also

Testing Mobile Web Applications Using Emulator
Creating Mobile Browser Profiles
VirtualBrowserInfo Object
ScreenHeight Property
DevicePixelRatio Property
UserAgent Property
Name Property
RunOptions Property

Highlight search results