Checking the Android and iOS Version (Legacy)

Applies to TestComplete 15.0, last modified on November 17, 2021
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.

Your application may behave differently depending on the version of the device’s operating system. For example, different iOS versions may have different user interfaces, and so do applications for these iOS versions. Mobile applications can also have functions that are only supported since a specific iOS or Android version. To handle this in your tests, you can check the version of the device’s operating system and run tests created for this version.

To check the mobile OS version, use the following properties of the Device object:

Both of them return the OS version as a string, for example "6.0" or "11.0".

Checking the OS Version in Keyword Tests

In keyword tests, use the Call Object Method operation to get the Android or iOS version. To configure this operation:

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

  • Enter one of the following as the object name:

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

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

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

    Click Next.

  • Select one of the following properties:

    • The VersionRelease property for Android devices,

    • The ProductVersion property for iOS devices.

  • Press Finish.

Right after the Call Object Method operation, add an operation that will use the OS version. 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 Android version from keyword tests

Checking the OS Version in Scripts

You may often need to learn the version of the device’s operating system to decide which tests to run next. For example (pseudocode):

if Android version > 6.0 then
  do something
else
  do something else

The device’s OSInfo.VersionRelease and OSInfo.ProductVersion properties return the version number as a string in the format major.minor.build.revision. You should parse version strings into numbers to work with them using comparison operators.

To learn only the major version, you can take the first character of the version string, convert it to a number and check it against the specified condition (for example, if it is greater than 10).

If you need to learn the minor or build version number, you can use the .NET Version class that has version parsing and comparison methods.

The examples below check whether the iOS and Android versions are equal to or greater than 10.0 and 6.0 respectively:

JavaScript, JScript

function getiOSVersion()
{
  Mobile.SetCurrent("iPhone X");

  var ver = Mobile.Device().OSInfo.ProductVersion;

  if (GreaterOrEqual(ver, "10.0"))
    Log.Message("iOS version is 10.0 or later.")
  else
    Log.Message("iOS version is earlier than 10.0.")
}

// Uses the .NET Version class to compare two version strings.
// Returns True if the first version string is greater than or equal to the second version.
// Otherwise, it returns False.
function GreaterOrEqual(VersionStr1, VersionStr2)
{
  var clsVersion = dotNET.System.Version;
  var ver1 = clsVersion.zctor_4(VersionStr1);
  var ver2 = clsVersion.zctor_4(VersionStr2);

  return clsVersion.op_GreaterThanOrEqual(ver1, ver2);
}

Python

def getiOSVersion():
  Mobile.SetCurrent("iPhone X")

  ver = Mobile.Device().OSInfo.ProductVersion

  if (GreaterOrEqual(ver, "10.0")):
    Log.Message("iOS version is 10.0 or later.")
  else:
    Log.Message("iOS version is earlier than 10.0.")

# Uses the .NET Version class to compare two version strings.
# Returns True if the first version string is greater than or equal to the second version.
# Otherwise, it returns False.
def GreaterOrEqual(VersionStr1, VersionStr2):
  clsVersion = dotNET.System.Version
  ver1 = clsVersion.zctor_4(VersionStr1)
  ver2 = clsVersion.zctor_4(VersionStr2)
  return clsVersion.op_GreaterThanOrEqual(ver1, ver2)

VBScript

Sub getiOSVersion
   Dim ver

   Call Mobile.SetCurrent("iPhone X")
   ver = Mobile.Device.OSInfo.ProductVersion

  If GreaterOrEqual(ver, "10.0") Then
    Log.Message("iOS version is 10.0 or later.")
  Else
    Log.Message("iOS version is earlier than 10.0.")
  End If
End Sub

' Uses the .NET Version class to compare two version strings.
' Returns True if the first version string is greater than or equal to the second version.
' Otherwise, it returns False.
Function GreaterOrEqual(VersionStr1, VersionStr2)
  Dim clsVersion, ver1, ver2

  Set clsVersion = dotNET.System.Version
  Set ver1 = clsVersion.zctor_4(VersionStr1)
  Set ver2 = clsVersion.zctor_4(VersionStr2)

  GreaterOrEqual = clsVersion.op_GreaterThanOrEqual(ver1, ver2)
End Function

DelphiScript

// Uses the .NET Version class to compare two version strings.
// Returns True if the first version string is greater than or equal to the second version.
// Otherwise, it returns False.
function GreaterOrEqual(VersionStr1, VersionStr2);
var clsVersion, ver1, ver2;
begin
  clsVersion := dotNET.System.Version;
  ver1 := clsVersion.zctor_4(VersionStr1);
  ver2 := clsVersion.zctor_4(VersionStr2);

  Result := clsVersion.op_GreaterThanOrEqual(ver1, ver2);
end;

procedure getiOSVersion;
var ver;
begin
  Mobile.SetCurrent('iPhone X');
  ver := Mobile.Device.OSInfo.ProductVersion;

  if GreaterOrEqual(ver, '10.0') then
    Log.Message('iOS version is 10.0 or later.')
  else
    Log.Message('iOS version is earlier than 10.0.');
end;

C++Script, C#Script

function getiOSVersion()
{
  Mobile["SetCurrent"]("iPhone X");
  var ver = Mobile["Device"]()["OSInfo"]["ProductVersion"];
 
  if (GreaterOrEqual(ver, "10.0"))
    Log["Message"]("iOS version is 10.0 or later.")
  else
    Log["Message"]("iOS version is earlier than 10.0")
}

// Uses the .NET Version class to compare two version strings.
// Returns True if the first version string is greater than or equal to the second version
// Otherwise, it returns False.
function GreaterOrEqual(VersionStr1, VersionStr2)
{
  var clsVersion = dotNET["System"].Version;
  var ver1 = clsVersion["zctor_4"](VersionStr1);
  var ver2 = clsVersion["zctor_4"](VersionStr2);

  return clsVersion["op_GreaterThanOrEqual"](ver1, ver2);
}

JavaScript, JScript

function getAndroidVersion()
{
  Mobile.SetCurrent("MyDevice");
  var ver = Mobile.Device().OSInfo.VersionRelease;
  
  if (GreaterOrEqual(ver, "6.0"))
    Log.Message("Android version is 6.0 or later.")
  else
    Log.Message("Android version is earlier than 6.0.")
}

// Uses the .NET Version class to compare two version strings.
// Returns True if the first version string is greater than or equal to the second version.
// Otherwise, it returns False.
function GreaterOrEqual(VersionStr1, VersionStr2)
{
  var clsVersion = dotNET.System.Version;
  var ver1 = clsVersion.zctor_4(VersionStr1);
  var ver2 = clsVersion.zctor_4(VersionStr2);

  return clsVersion.op_GreaterThanOrEqual(ver1, ver2);
}

Python

def getAndroidVersion():
  Mobile.SetCurrent("MyDevice")
  ver = Mobile.Device().OSInfo.VersionRelease
  
  if (GreaterOrEqual(ver, "6.0")):
    Log.Message("Android version is 6.0 or later.")
  else:
    Log.Message("Android version is earlier than 6.0.")

# Uses the .NET Version class to compare two version strings.
# Returns True if the first version string is greater than or equal to the second version.
# Otherwise, it returns False.
def GreaterOrEqual(VersionStr1, VersionStr2):
  clsVersion = dotNET.System.Version
  ver1 = clsVersion.zctor_4(VersionStr1)
  ver2 = clsVersion.zctor_4(VersionStr2)
  return clsVersion.op_GreaterThanOrEqual(ver1, ver2)

VBScript

Sub getAndroidVersion
  Dim ver

  Mobile.SetCurrent("MyDevice")
  ver = Mobile.Device.OSInfo.VersionRelease

  If GreaterOrEqual(ver, "6.0") Then
    Log.Message("Android version is 6.0 or later.")
  Else
    Log.Message("Android version is earlier than 6.0.")
  End If
End Sub

' Uses the .NET Version class to compare two version strings.
' Returns True if the first version string is greater than or equal to the second version.
' Otherwise, it returns False.
Function GreaterOrEqual(VersionStr1, VersionStr2)
  Dim clsVersion, ver1, ver2

  Set clsVersion = dotNET.System.Version
  Set ver1 = clsVersion.zctor_4(VersionStr1)
  Set ver2 = clsVersion.zctor_4(VersionStr2)

  GreaterOrEqual = clsVersion.op_GreaterThanOrEqual(ver1, ver2)
End Function

DelphiScript

// Uses the .NET Version class to compare two version strings.
// Returns True if the first version string is greater than or equal to the second version.
// Otherwise, it returns False.
function GreaterOrEqual(VersionStr1, VersionStr2);
var clsVersion, ver1, ver2;
begin
  clsVersion := dotNET.System.Version;
  ver1 := clsVersion.zctor_4(VersionStr1);
  ver2 := clsVersion.zctor_4(VersionStr2);

  Result := clsVersion.op_GreaterThanOrEqual(ver1, ver2);
end;

procedure getAndroidVersion;
var ver;
begin
  Mobile.SetCurrent('MyDevice');
  ver := Mobile.Device.OSInfo.VersionRelease;

  if GreaterOrEqual(ver, '6.0') then
    Log.Message('Android version is 6.0 or later.')
  else
    Log.Message('Android version is earlier than 6.0.');
end;

C++Script, C#Script

function getAndroidVersion()
{
  Mobile["SetCurrent"]("MyDevice");
  var ver = Mobile["Device"].OSInfo["VersionRelease"];
  
  if (GreaterOrEqual(ver, "6.0"))
    Log["Message"]("Android version is 6.0 or later.")
  else
    Log["Message"]("Android version is earlier than 6.0")
}

// Uses the .NET Version class to compare two version strings.
// Returns True if the first version string is greater than or equal to the second version
// Otherwise, it returns False.
function GreaterOrEqual(VersionStr1, VersionStr2)
{
  var clsVersion = dotNET["System"].Version;
  var ver1 = clsVersion["zctor_4"](VersionStr1);
  var ver2 = clsVersion["zctor_4"](VersionStr2);

  return clsVersion["op_GreaterThanOrEqual"](ver1, ver2);
}

Note: You can run these scripts from keyword tests using the Run Script Routine operation.

See Also

AndroidOSInfo Object
iOSOSInfo Object

Highlight search results