Running Tests on Multiple Devices (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.

It is important to test a mobile application on different devices (smartphones, tablets and other devices) to ensure that it works correctly on all of them. With TestComplete, you can create your test once and then play it back on all the available devices running the same mobile operating system. This topic explains how you can do this.

Considerations for Multi-Device Tests

When testing Android or iOS applications that were prepared in a special way (see Preparing for Testing Android Applications (Legacy) and Preparing Applications, Devices, and Test Computers for iOS Testing (Legacy)), TestComplete gets access to the internals of the application under test. This allows you to create a test that will work directly with application controls' methods and properties. In this case, your test does not depend on the current device’s properties. So, a test created on one device can be played back on another device with little or no modifications.

To test unprepared Android applications, you can also use the image-based testing approach: search for the desired control using its image, and simulate user actions over the found control. Running image-based tests on another device requires more efforts, as different devices can have different screen resolutions, screen orientations, color themes and so on. In order for an image-based test can be played back on another device, you need to add all possible variants of the object appearance to the image repository.

Creating Multi-Device Keyword Tests

To perform the same test on multiple mobile devices, you can use the Device Loop keyword operation. This operation is analogous to the Select Device operation but oriented on multi-device tests: in this operation you define a list of devices where test actions will be performed: these can be all connected devices or just some specific devices. During the test run TestComplete executes child operations on each of the devices from the list, one after another.

A sample multi-device keyword test
A sample multi-device keyword test

Creating Multi-Device Scripts

The TestComplete Mobile object provides access to all mobile devices (no matter physical or virtual) connected to TestComplete and allows you to iterate through the devices. You can use the Mobile.ChildCount property to get the number of the connected devices, and the Mobile.Child(...) property to access a specific device. Using these properties, you can write a loop to iterate through the connected devices and run the test on each of them in turn.

JavaScript, JScript

function IterateDevice() {
  var device;
  for (var i = 0; i < Mobile.ChildCount; i++){
    device = Mobile.Child(i);
    // Setting the current device
    Mobile.SetCurrent(device.DeviceName, device.Index)
    // Perform a mobile test
    Log.Picture(Mobile.Device().Desktop.Picture());
  }
}

Python

def IterateDevice():
  for i in range (0, Mobile.ChildCount):
    device = Mobile.Child(i);
    # Setting the current device
    Mobile.SetCurrent(device.DeviceName, device.Index)
    # Perform a mobile test
    Log.Picture(Mobile.Device().Desktop.Picture());

VBScript

Sub IterateDevice
  Dim device, i
  For i = 0 to Mobile.ChildCount - 1
    Set device = Mobile.Child(i)
    ' Setting the current device
    Call Mobile.SetCurrent(device.DeviceName, device.Index)
    ' Perform a mobile test
    Call Log.Picture(Mobile.Device.Desktop.Picture())
  Next
End Sub

DelphiScript

procedure IterateDevice;
var device, i;
begin
  for i :=0 to Mobile.ChildCount - 1 do
  begin
    device := Mobile.Child(i);
    // Setting the current device
    Mobile.SetCurrent(device.DeviceName, device.Index);
    // Perform a mobile test
    Log.Picture(Mobile.Device.Desktop.Picture())
  end;
end;

C++Script, C#Script

function IterateDevice()
{
  var device;
  for (var i = 0; i < Mobile["ChildCount"]; i++)
  {
    device = Mobile["Child"](i);
    // Setting the current device
    Mobile["SetCurrent"](device["DeviceName"], device["Index"]);
    // Perform a mobile test
    Log["Picture"](Mobile["Device"]["Desktop"]["Picture"]());
  }
}

Alternatively, you can use the Utils.Enumerator method or language-specific statements to enumerate the Mobile device collection: in VBScript, enumeration is done by using the For Each statement; in JScript, Python, C++Script and C#Script - the Enumerator object. (DelphiScript does not provide a native way to create an enumerator loop.)

JavaScript

function EnumTest()
{
  for (let device of Mobile)
  {
    // Setting the current device
    Mobile.SetCurrent(device.DeviceName, device.Index)
    // Perform a mobile test
    Log.Picture(Mobile.Device().Desktop.Picture());
  }
}

JScript

function EnumTest()
{
  var deviceEnum = new Enumerator(Mobile)
  while (!deviceEnum.atEnd())
  {
    var device = deviceEnum.item();
    // Setting the current device
    Mobile.SetCurrent(device.DeviceName, device.Index)
    // Perform a mobile test
    Log.Picture(Mobile.Device().Desktop.Picture());
    deviceEnum.moveNext();
  }
}

Python

def EnumTest():
  deviceEnum = Enumerator(Mobile);
  while not deviceEnum.AtEnd:
    device = deviceEnum.Item;
    # Setting the current device
    Mobile.SetCurrent(device.DeviceName, device.Index)
    # Perform a mobile test
    Log.Picture(Mobile.Device().Desktop.Picture());
    deviceEnum.moveNext();

VBScript

Sub EnumTest
  For Each device In Mobile
    ' Setting the current device
    Call Mobile.SetCurrent(device.DeviceName, device.Index)
    ' Perform a mobile test
    Call Log.Picture(Mobile.Device.Desktop.Picture())
  Next
End Sub

DelphiScript

procedure EnumTest;
var deviceEnum, device;
begin
  deviceEnum := Utils.Enumerator(Mobile);
  while not deviceEnum.AtEnd do
  begin
    device:= deviceEnum.item;
    // Setting the current device
    Mobile.SetCurrent(device.DeviceName, device.Index);
    // Perform a mobile test
    Log.Picture(Mobile.Device.Desktop.Picture());
    deviceEnum.moveNext;
  end;
end;

C++Script, C#Script

function EnumTest()
{
  var device;
  var deviceEnum = new Enumerator(Mobile);
  while (!deviceEnum["atEnd"]())
  {
    device = deviceEnum["item"]();
    // Setting the current device
    Mobile["SetCurrent"](device["DeviceName"], device["Index"]);
    // Perform a mobile test
    Log["Picture"](Mobile["Device"]["Desktop"]["Picture"]());
    deviceEnum["moveNext"]();
  }
}

Verifying the Mobile Platform Prior to Test Actions

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 prior to performing test actions. To do this, you can check the OSType property of the test object corresponding to the desired mobile device. For details and samples, see Verifying the Mobile Platform (OS Type) (Legacy).

However, we recommend that you address the desired device by its mapped name or alias: NameMapping.Mobile.Device or Aliases.Device. In this case, the device running another OS will not be recognized as suitable for the test, since the value of the OSType property is used as the default recognition attribute when mapping a mobile device. That is, if you use a name mapping notation in script or in a keyword test, verification of the mobile OS type will be performed implicitly.

Adapting Tests to Multiple Mobile Devices

Since most mobile devices are different (they have a different screen size, density, orientation, operating system version, etc.), you may face a situation when a test recorded on one mobile device cannot be played back successfully on another mobile device. To learn how to work around this issue, see the Adapting Tests to Mobile Devices of Different Types (Legacy) topic.

See Also

Preparing for Testing Android Applications (Legacy)
Preparing Applications, Devices, and Test Computers for iOS Testing (Legacy)
Adapting Tests to Mobile Devices of Different Types (Legacy)
Image-Based Testing
Mobile Object

Highlight search results