Addressing Objects in Mobile Applications Running in Mobile Device Clouds

Applies to TestComplete 14.74, last modified on April 22, 2021

To simulate user actions over your tested mobile application running in a mobile device cloud (it can be the device cloud provided by BitBar or a private cloud managed by Appium), locate the needed object in the application first.

Currently, Name Mapping is not supported for mobile applications running in device clouds.

Requirements and prerequisites

Before exploring the tested application and locating tested objects, make sure that all requirements and prerequisites are met:

Addressing objects by their unique identifier

The easiest way to locate objects in your tested mobile application is to use the unique search expression that TestComplete provides for each object it recognizes in your tested mobile application. The Object Browser of TestComplete shows the list of available search expressions (if several expressions are available):

Viewing the object's name in Object Browser

Click the image to enlarge it.

You can copy the expression to the clipboard and then insert it into your test.

Addressing objects in script tests

To address a tested object, you can use various FindElement methods:

For example, the code snippet below shows how to use the FindElementById method to get an object in a tested mobile application:

JavaScript

function Test()
{

  …
  var device = Mobile.Device("MyDevice");
  var list = device.FindElementById("smartbear.example.orders:id/listView1");
  …

}

Python

def Test():
  …
  device = Mobile.Device("MyDevice")
  list = device.FindElementById("smartbear.example.orders:id/listView1")
  …

VBScript

Sub Test
  …
  Set device = Mobile.Device("MyDevice")
  Set list = device.FindElementById("smartbear.example.orders:id/listView1")
  …

End Sub

DelphiScript

procedure Test();
var device, list;
begin
  …
  device := Mobile.Device('MyDevice');
  list := device.FindElementById('smartbear.example.orders:id/listView1');
  …

end;

C++Script, C#Script

function Test()
{

  …
  var device = Mobile["Device"]("MyDevice");
  var list = device["FindElementById"]("smartbear.example.orders:id/listView1");
  …

}

To pause the test run until the needed object becomes available, you can use various WaitElement methods:

The code snippet below shows how to pause the test run until a tested object with the specified ID becomes available:

JavaScript

function Test()
{

  …
  var device = Mobile.Device("MyDevice");
  var list = device.WaitElementById("smartbear.example.orders:id/listView1", 3000);
  …

}

Python

def Test():
  …
  device = Mobile.Device("MyDevice")
  list = device.WaitElementById("smartbear.example.orders:id/listView1", 3000)
  …

VBScript

Sub Test
  …
  Set device = Mobile.Device("MyDevice")
  Set list = device.WaitElementById("smartbear.example.orders:id/listView1", 3000)
  …

End Sub

DelphiScript

procedure Test();
var device, list;
begin
  …
  device := Mobile.Device('MyDevice');
  list := device.WaitElementById('smartbear.example.orders:id/listView1', 3000);
  …

end;

C++Script, C#Script

function Test()
{

  …
  var device = Mobile["Device"]("MyDevice");
  var list = device["WaitElementById"]("smartbear.example.orders:id/listView1", 3000);
  …

}

To get all tested objects that match a search condition, you can use various FindElements methods:

The code snippet below shows how to get all objects with the specified class name:

JavaScript

function Test()
{
  var items = Mobile.Device("MyDevice").FindElementsByClassName("android.widget.TwoLineListItem");
  for (let i = 0; i < items.length; i++)
  {
    …
  }
}

Python

def Test():
  items = Mobile.Device("MyDevice").FindElementsByClassName("android.widget.TwoLineListItem");
  for i in range (0, len(items) - 1):
    …

VBScript

Sub Test
  items = Mobile.Device("MyDevice").FindElementsByClassName("android.widget.TwoLineListItem")
  For i = 0 To UBound(items)
    …
  Next
End Sub

DelphiScript

procedure Test();
var items, i;
begin
  items := Mobile.Device('MyDevice').FindElementsByClassName('android.widget.TwoLineListItem');
  for i := 0 to VarArrayHighBound(items, 1) do
  begin
    …
  end;
end;

C++Script, C#Script

function Test()
{
  var items = Mobile["Device"]("MyDevice")["FindElementsByClassName"]("android.widget.TwoLineListItem");
  for (let i = 0; i < items["length"]; i++)
  {
    …
  }
}

Addressing objects in keyword tests

To get the needed objects in keyword tests, you can do the following:

  1. In the Object Browser, locate the needed object in your tested application hierarchy.

  2. Copy the search expression that TestComplete provides for the object:

    Copying object identifier in Object Browser

    Click the image to enlarge it.

  3. In your keyword test, add the operation you want to run against the object (for example, the On-Screen Action operation), and when configuring the operation, use the copied expression to specify the target object.

    Specifying a tested object in a keyword test

    Click the image to enlarge it.

See Also

About Running Mobile Tests in Mobile Device Clouds

Highlight search results