Verifying the Mobile Platform (OS Type) (Legacy)

Applies to TestComplete 15.48, last modified on March 01, 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.

Several Android and iOS devices can be connected to the same computer simultaneously. Tests created for Android devices cannot be executed on iOS devices and vice versa. Attempts to run a test on an inappropriate platform will most likely cause errors. To avoid such situations, you can check the type of the mobile operating system before performing any test actions.

Besides, some objects or members may have similar functionality, but their names may be different on different platforms. To address the appropriate object or member, you need to know which operating system is running on the current device as well.

To determine the type of the mobile operating system, read the OSType property of the object that corresponds to the desired mobile device. This property returns the type of the operating system installed on the device: Android or iOS.

Verifying the Mobile Platform in Keyword Tests

In keyword tests, use the If...Then operation to verify the type of the mobile OS. To configure this operation:

  • Add the If... Then operation to your keyword test. TestComplete will display the Operation Parameters wizard.

  • In the Value 1 column, enter one of the following:

    • Aliases.Device.OSType - if you use Name Mapping,

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

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

  • In the Condition column, select the desired condition: either Equals or Not equals.

  • In the Value 2 column, enter the name of the operating system to be checked: Android or iOS.

  • Click Finish.

  • Add the operations to be performed after the verification is complete as child operations of the If...Then operation.

The following keyword test verifies the mobile platform and proceeds to test actions only if the device runs Android.

Verifying mobile platform in keyword tests

Verifying the Mobile Platform in Scripts

To verify the mobile platform in scripts, you can compare the value of the OSType property within the if...then statements.

The following script verifies the mobile platform and proceeds to test actions only if the device runs Android.

JavaScript, JScript

function TestWithOSTypeVerification()
{
     ...
     // Verify the mobile OS type
     if (Mobile.Device().OSType!="Android")
      {
         Log.Warning("This test is for Android devices only.")
         // Exit the test for the current device
         return;
      }
     // Perform a mobile test for Android devices
     ...
}

Python

def TestWithOSTypeVerification():
     # ...
     # Verify the mobile OS type
     if (Mobile.Device().OSType != "Android"):
         Log.Warning("This test is for Android devices only.")
         # Exit the test for the current device
         return; 
     # Perform a mobile test for Android devices
     # ...

VBScript

Sub TestWithOSTypeVerification
     ...
     ' Verify the mobile OS type
     If (Mobile.Device.OSType<>"Android")Then
         Log.Warning("This test is for Android devices only.")
         ' Exit the test for the current device
         Exit Sub
      End If
      
     ' Perform a mobile test for Android devices
     ...
End Sub

DelphiScript

procedure TestWithOSTypeVerification;
begin
     ...
     // Verify the mobile OS type
     if (Mobile.Device.OSType<>'Android') then
      begin
         Log.Warning('This test is for Android devices only.');
         // Exit the test for the current device
         exit;
      end;
     // Perform a mobile test for Android devices
     ...
end;

C++Script, C#Script

function TestWithOSTypeVerification()
{
     ...
     // Verify the mobile OS type
     if (Mobile["Device"]["OSType"] != "Android")
      {
         Log["Warning"]("This test is for Android devices only.")
         // Exit the test for the current device
         return;
      }
     // Perform a mobile test for Android devices
     ...
}

Implicit Verification Through Name Mapping

If you address a mobile device using its mapped name or alias (NameMapping.Mobile.Device or Aliases.Device) and the mapped name was created automatically, then the verification of the mobile OS type is performed implicitly. This is because the value of the OSType property is used as the default mapping criterion for the objects that represent the mobile device. This helps TestComplete choose the appropriate mobile device for the test automatically (a script or in a keyword test).

Suppose, an Android device and an iOS device are connected to your computer and you have a keyword test that works with an Android application. When you start this test, TestComplete will automatically select the Android device, since the iOS device will not match the mapping criterion.

See Also

OSType Property
Running Tests on Multiple Devices (Legacy)

Highlight search results