Toolbars and navigation bars may contain items of different types. TestComplete works with different item types in the same way. However, you may need to know the type of the item you are using in order to perform certain actions. This topic explains how you can do this in scripts.
Checking the Item Type in Scripts
The iOS ToolBar
and iOS NavigationBar
objects provide scripting access to different kinds of controls and contain special properties that let you determine the control type:
-
wIsDropDownItem
– returns True if the item is a drop down list. -
wIsItemSwitchable
– returns True if the item is a switch. -
wIsSeparatorItem
– returns True if the item is a separator.
These properties have the Item parameter that specifies the desired item (see Addressing Tool Bar and Navigation Bar Items).
The following example iterates through toolbar items, determines the type of each item and posts it to the test log.
JavaScript, JScript
function Test()
{
// Select the mobile device
Mobile.SetCurrent("iPhone");
// Obtain the Toolbar object
var p = Mobile.Device().Process("SampleApp");
var toolbar = p.Window().Toolbar();
// Iterate through the items
for (var i=0; i<toolbar.wItemCount; i++)
{
// Post the item type to the log
if (toolbar.wIsDropDownItem(i))
Log.Message("Item "+i+" is a drop-down list.")
if (toolbar.wIsItemSwitchable(i))
Log.Message("Item "+i+" is a switch.")
if (toolbar.wIsSeparatorItem(i))
Log.Message("Item "+i+" is a separator.")
}
}
Python
def Test():
# Select the mobile device
Mobile.SetCurrent("iPhone")
# Obtain the Toolbar object
p = Mobile.Device().Process("SampleApp")
toolbar = p.Window().Toolbar()
# Iterate through the items
for i in range(0, toolbar.wItemCount):
# Post the item type to the log
if (toolbar.wIsDropDownItem[i]):
Log.Message("Item "+str(i)+" is a drop-down list.")
if (toolbar.wIsItemSwitchable[i]):
Log.Message("Item "+str(i)+" is a switch.")
if (toolbar.wIsSeparatorItem[i]):
Log.Message("Item "+str(i)+" is a separator.")
VBScript
Sub Test()
Dim p, toolbar
' Select the mobile device
Mobile.SetCurrent("iPhone")
' Obtain the Toolbar object
Set p = Mobile.Device.Process("SampleApp")
Set toolbar = p.Window(0).Toolbar()
' Iterate through the items
For i = 0 To toolbar.wItemCount-1
' Post the item type to the log
If (toolbar.wIsDropDownItem(i)) Then
Log.Message("Item " & i & " is a drop-down list.")
End If
If (toolbar.wIsItemSwitchable(i)) Then
Log.Message("Item "+i+" is a switch.")
End If
If (toolbar.wIsSeparatorItem(i)) Then
Log.Message("Item "+i+" is a separator.")
End If
Next
End Sub
DelphiScript
procedure Test();
var
i, p, toolbar;
begin
// Select the mobile device
Mobile.SetCurrent('iPhone');
// Obtain the Toolbar object
p := Mobile.Device.Process('SampleApp');
toolbar := p.Window(0).Toolbar(0);
// Iterate through the items
for i := 0 to toolbar.wItemCount-1 do
begin
// Post the item type to the log
if toolbar.wIsDropDownItem(i) then
Log.Message('Item '+VarToStr(i)+' is a drop-down list.');
if toolbar.wIsItemSwitchable(i) then
Log.Message('Item '+VarToStr(i)+' is a switch.');
if toolbar.wIsSeparatorItem(i)then
Log.Message('Item '+VarToStr(i)+' is a separator.');
end;
end;
C++Script, C#Script
function Test()
{
// Select the mobile device
Mobile["SetCurrent"]("iPhone");
// Obtain the Toolbar object
var p = Mobile["Device"].Process("SampleApp");
var toolbar = p["Window"]()["Toolbar"]();
// Iterate through the items
for (var i=0; i<toolbar["wItemCount"]; i++)
{
// Post the item type to the log
if (toolbar["wIsDropDownItem"](i))
Log["Message"]("Item "+i+" is a drop-down list.")
if (toolbar["wIsItemSwitchable"](i))
Log["Message"]("Item "+i+" is a switch.")
if (toolbar["wIsSeparatorItem"](i))
Log["Message"]("Item "+i+" is a separator.")
}
}
Simulating Actions in Keyword Tests
To check the type of the tool and navigation bar items from keyword tests, use the On-Screen Action or Call Object Method operation to access the properties described above. See Getting and Setting Object Property Values.
See Also
Working With iOS Toolbar and Navigation Bar Controls
Checking the State of Toolbar and Navigation Bar Items