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):
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
{
…
var device = Mobile.Device("MyDevice");
var list = device.FindElementById("smartbear.example.orders:id/listView1");
…
}
Python
…
device = Mobile.Device("MyDevice")
list = device.FindElementById("smartbear.example.orders:id/listView1")
…
VBScript
…
Set device = Mobile.Device("MyDevice")
Set list = device.FindElementById("smartbear.example.orders:id/listView1")
…
End Sub
DelphiScript
var device, list;
begin
…
device := Mobile.Device('MyDevice');
list := device.FindElementById('smartbear.example.orders:id/listView1');
…
end;
C++Script, C#Script
{
…
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
{
…
var device = Mobile.Device("MyDevice");
var list = device.WaitElementById("smartbear.example.orders:id/listView1", 3000);
…
}
Python
…
device = Mobile.Device("MyDevice")
list = device.WaitElementById("smartbear.example.orders:id/listView1", 3000)
…
VBScript
…
Set device = Mobile.Device("MyDevice")
Set list = device.WaitElementById("smartbear.example.orders:id/listView1", 3000)
…
End Sub
DelphiScript
var device, list;
begin
…
device := Mobile.Device('MyDevice');
list := device.WaitElementById('smartbear.example.orders:id/listView1', 3000);
…
end;
C++Script, C#Script
{
…
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:
FindElements
FindElementsByAccessibiltyId
FindElementsByClassName
FindElementsById
FindElementsByXPath
The code snippet below shows how to get all objects with the specified class name:
JavaScript
{
var items = Mobile.Device("MyDevice").FindElementsByClassName("android.widget.TwoLineListItem");
for (let i = 0; i < items.length; i++)
{
…
}
}
Python
items = Mobile.Device("MyDevice").FindElementsByClassName("android.widget.TwoLineListItem");
for i in range (0, len(items) - 1):
…
VBScript
items = Mobile.Device("MyDevice").FindElementsByClassName("android.widget.TwoLineListItem")
For i = 0 To UBound(items)
…
Next
End Sub
DelphiScript
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
{
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:
-
In the Object Browser, locate the needed object in your tested application hierarchy.
-
Copy the search expression that TestComplete provides for the object:
-
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.