Tab bar controls in iOS applications are usually used to allow a user to switch among a set of application’s views. To switch to a desired view, a user selects an appropriate tab bar item.
When testing iOS applications, before you simulate actions on the controls that belong to the application’s view, you may need to determine which tab bar item is currently selected. This topic describes how to check which tab bar item is selected from tests.
Determining the Selected Tab Bar Item
To check which tab bar item is currently selected, use the wFocusedTab
property of the iOS TabBar
test object that TestComplete associates with that control. The property returns the zero-based index of the selected tab bar item.
The following sample code checks whether the first tab bar item of the tab bar control is selected and if it is not, the code simulates a touch on the first tab bar item to select it.
JavaScript, JScript
{
// Select the mobile device
Mobile.SetCurrent("iPhone");
// Obtain the TabBar object
var p = Mobile.Device().Process("SampleApp");
var tabBar = p.Window(0).TabBar();
// Check if the first tab bar item is selected
if (tabBar.wFocusedTab == 0)
Log.Message("The first tab is selected");
else
tabBar.TouchTab(0);
}
Python
def Test():
# Select the mobile device
Mobile.SetCurrent("iPhone")
# Obtain the TabBar object
p = Mobile.Device().Process("SampleApp")
tabBar = p.Window(0).TabBar()
# Check if the first tab bar item is selected
if (tabBar.wFocusedTab == 0):
Log.Message("The first tab is selected")
else:
tabBar.TouchTab(0)
VBScript
' Select the mobile device
Mobile.SetCurrent("iPhone")
' Obtain the TabBar object
Set p = Mobile.Device.Process("SampleApp")
Set tabBar = p.Window(0).TabBar
' Check if the first tab bar item is selected
If tabBar.wFocusedTab = 0 Then
Log.Message("The first tab is selected")
Else
tabBar.TouchTab(0)
End If
End Sub
DelphiScript
var p, tabBar;
begin
// Select the mobile device
Mobile.SetCurrent('iPhone');
// Obtain the TabBar object
p := Mobile.Device.Process('SampleApp');
tabBar := p.Window(0).TabBar();
// Check if the first tab bar item is selected
if tabBar.wFocusedTab = 0 then
Log.Message('The first tab is selected')
else
tabBar.TouchTab(0);
end;
C++Script, C#Script
{
// Select the mobile device
Mobile["SetCurrent"]("iPhone");
// Obtain the TabBar object
var p = Mobile["Device"]["Process"]("SampleApp");
var tabBar = p["Window"](0)["TabBar"]();
// Check if the first tab bar item is selected
if (tabBar["wFocusedTab"] == 0)
Log["Message"]("The first tab is selected");
else
tabBar["TouchTab"](0);
}
Determining the Selected Tab Bar Item From Keyword Tests
To determine the selected tab bar item 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 TabBar Controls
wFocusedTab Property (Mobile Controls)
Determining the Number of Tab Bar Items