Determining and Changing Time Using Time Picker Control

Applies to TestComplete 15.62, last modified on March 19, 2024
Getting and Assigning wTime Property

To determine or change the time displayed on the time picker control, use the wTime property of the Android TimePicker object that TestComplete associates with that control. The value this property returns corresponds the regional settings of the machine performing the test. The value you want to assign must follow the same format, otherwise the error will occur. The following example checks the time of the time picker, posts it to the log and changes it:

JavaScript, JScript

function Test()
{
  // Select the Android device
  Mobile.SetCurrent("MyDevice");

  // Obtain the CalendarView object
  var p = Mobile.Device().Process("com.example.myapp");
  var TimePicker = p.RootLayout("", 2).Layout("content").TimePicker("timePicker");
  
  // Get the current time
  var TimeNow = TimePicker.wTime;
  
  // Post it to the log
  Log.Message(TimeNow);
  
  // Change the time
  TimePicker.wTime = "11:11:11 AM";
}

Python

def Test():
  # Select the Android device
  Mobile.SetCurrent("MyDevice")

  # Obtain the CalendarView object
  p = Mobile.Device().Process("com.example.myapp")
  TimePicker = p.RootLayout("", 2).Layout("content").TimePicker("timePicker")
  
  # Get the current time
  TimeNow = TimePicker.wTime
  
  # Post it to the log
  Log.Message(TimeNow)
  
  # Change the time
  TimePicker.wTime = "11:11:11 AM"

VBScript

Sub Test()
  ' Select the Android device
  Call Mobile.SetCurrent("MyDevice")

  ' Obtain the CalendarView object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set TimePicker = p.RootLayout("", 2).Layout("content").TimePicker("timePicker")
  
  ' Get the current time
  TimeNow = TimePicker.wTime
  
  ' Post it to the log
  Log.Message(TimeNow)
  
  ' Change the time
  TimePicker.wTime = "11:11:11 AM"
End Sub

DelphiScript

procedure Test();
var
  p, TimePicker, TimeNow : OleVariant;
begin
  // Select the Android device
  Mobile.SetCurrent('MyDevice');

  // Obtain the TimePicker object
  p := Mobile.Device.Process('com.example.myapp');
  TimePicker := p.RootLayout('', 2).Layout('content').TimePicker('timePicker');
  
  // Get the current time
  TimeNow := TimePicker.wTime;
  
  // Post it to the log
  Log.Message(TimeNow);
  
  // Change the time
  TimePicker.wTime := '11:11:11 AM';
end;

C++Script, C#Script

function Test()
{
  // Select the Android device
  Mobile["SetCurrent"]("MyDevice");

  // Obtain the TimePicker object
  var p = Mobile["Device"]["Process"]("com.example.myapp");
  var TimePicker = p["RootLayout"]("", 2)["Layout"]("content")["TimePicker"]("timePicker");
  
  // Get the current time
  var TimeNow = TimePicker.wTime;
  
  // Post it to the log
  Log["Message"](TimeNow);
  
  // Change the time
  TimePicker.wTime = "11:11:11 AM";
}

Working With Number Pickers

A time picker control has NumberPicker child objects. You can set the needed time by changing their position. To set hours and minutes, specify the required value in the wPosition property. To set am or pm, specify 0 or 1 respectively.

However, in most cases, it is easier to use methods and properties of time picker controls, as in this case, the details of control implementation are hidden from tests. For more information on working with number picker controls, see the topics of the Working With Number Picker Controls section.

Simulating Actions From Keyword Tests

This topic explains how to set the time on the time picker control in scripts. You can use the described methods in keyword tests too. To do this, use the On-Screen Action or the Call Object Method operations.

See Also

Working With Android Time Picker Controls
Determining Time Picker's Format
Touch Action (Mobile Objects)
wTime Property (Android Controls)

Highlight search results