Determining and Changing Calendar Date

Applies to TestComplete 15.47, last modified on January 20, 2023
Determining the Calendar Date
Getting wDate Property

To determine the date of a calendar control, use the wDate property of the Android CalendarView object that TestComplete associates with that control. The date format of the wDate property depends on the regional setting of the machine performing the test, not the settings of the mobile device. The following example checks the date on the calendar and posts it to the log:

JavaScript, JScript

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

  // Obtain the CalendarView object
  var p = Mobile.Device().Process("com.example.myapp");
  var CalendarView = p.RootLayout("").Layout("layoutTop").Layout("layout2").CalendarView("calendarView1");
  
  // Get the calendar date
  var CalendarDate = CalendarView.wDate;
  
  // Post the date to the log
  Log.Message(CalendarDate);
}

Python

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

  # Obtain the CalendarView object
  p = Mobile.Device().Process("com.example.myapp")
  CalendarView = p.RootLayout("").Layout("layoutTop").Layout("layout2").CalendarView("calendarView1")
  
  # Get the calendar date
  CalendarDate = CalendarView.wDate
  
  # Post the date to the log
  Log.Message(CalendarDate)

VBScript

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

  ' Obtain the CalendarView object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set CalendarView = p.RootLayout("").Layout("layoutTop").Layout("layout2").CalendarView("calendarView1")
  
  ' Get the calendar date
  CalendarDate = CalendarView.wDate
  
  ' Post the date to the log
  Log.Message(CalendarDate)
End Sub

DelphiScript

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

  // Obtain the CalendarView object
  p := Mobile.Device.Process('com.example.myapp');
  CalendarView := p.RootLayout('').Layout('layoutTop').Layout('layout2').CalendarView('calendarView1');
  
  // Get the calendar date
  CalendarDate := CalendarView.wDate;
  
  // Post the date to the log
  Log.Message(CalendarDate);
end;

C++Script, C#Script

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

  // Obtain the CalendarView object
  var p = Mobile["Device"]["Process"]("com.example.myapp");
  var CalendarView = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout2")["CalendarView"]("calendarView1");
  
  // Get the calendar date
  var CalendarDate = CalendarView["wDate"];
  
  // Post the date to the log
  Log["Message"](CalendarDate);
}

Changing the Calendar Date
Assigning wDate Property

To change the date of a calendar control, assign the required value to the wDate property. The value you want to assign must follow the regional standards of the machine performing the test, otherwise the error will occur. The following example sets the date of the calendar control to January 1, 2014:

JavaScript, JScript

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

  // Obtain the CalendarView object
  var p = Mobile.Device().Process("com.example.myapp");
  var CalendarView = p.RootLayout("").Layout("layoutTop").Layout("layout2").CalendarView("calendarView1");
  
  // Set the calendar date
  CalendarView.wDate = "01/01/2014";
}

Python

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

  # Obtain the CalendarView object
  p = Mobile.Device().Process("com.example.myapp")
  CalendarView = p.RootLayout("").Layout("layoutTop").Layout("layout2").CalendarView("calendarView1")
  
  # Set the calendar date
  CalendarView.wDate = "01/01/2014"

VBScript

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

  ' Obtain the CalendarView object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set CalendarView = p.RootLayout("").Layout("layoutTop").Layout("layout2").CalendarView("calendarView1")
  
  ' Set the calendar date
  CalendarView.wDate = "01/01/2014"
End Sub

DelphiScript

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

  // Obtain the CalendarView object
  p := Mobile.Device.Process('com.example.myapp');
  CalendarView := p.RootLayout('').Layout('layoutTop').Layout('layout2').CalendarView('calendarView1');
  
  // Set the calendar date
  CalendarView.wDate := '01/01/2014';
end;

C++Script, C#Script

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

  // Obtain the CalendarView object
  var p = Mobile["Device"]["Process"]("com.example.myapp");
  var Calendar = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout2")["CalendarView"]("calendarView1");
  
  // Set the calendar date
  Calendar["wDate"] = "01/01/2014";
}

Simulating Touch Action

To perform a touch of a calendar control, use the Touch action. This action performs a single short touch at the coordinates defined by the action's properties. To change the dates visible on the calendar, you can use the Swipe action of the device object. The following example performs the swipe over the calendar and then chooses a date:

JavaScript, JScript

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

  // Obtain the CalendarView object
  var p = Mobile.Device().Process("com.example.myapp");
  var CalendarView = p.RootLayout("").Layout("layoutTop").Layout("layout2").CalendarView("calendarView1");
  
  // Swipe the device to change dates
  Mobile.Device().Swipe(200, 200, 200, 300);
  
  // Touch the date by coordinates
  CalendarView.Touch(110, 90);
  
  // Get the calendar date
  var CalendarDate = CalendarView.wDate;
  
  // Post the date to the log
  Log.Message(CalendarDate);
}

Python

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

  # Obtain the CalendarView object
  p = Mobile.Device().Process("com.example.myapp")
  CalendarView = p.RootLayout("").Layout("layoutTop").Layout("layout2").CalendarView("calendarView1")
  
  # Swipe the device to change dates
  Mobile.Device().Swipe(200, 200, 200, 300)
  
  # Touch the date by coordinates
  CalendarView.Touch(110, 90)
  
  # Get the calendar date
  CalendarDate = CalendarView.wDate
  
  # Post the date to the log
  Log.Message(CalendarDate)

VBScript

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

  ' Obtain the CalendarView object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set CalendarView = p.RootLayout("").Layout("layoutTop").Layout("layout2").CalendarView("calendarView1")
  
  ' Swipe the device to change dates
  Call Mobile.Device.Swipe (200, 200, 200, 300)
  
  ' Touch the date by coordinates
  Call CalendarView.Touch(110, 90)

  ' Get the calendar date
  CalendarDate = CalendarView.wDate
  
  ' Post the date to the log
  Log.Message(CalendarDate)
End Sub

DelphiScript

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

  // Obtain the CalendarView object
  p := Mobile.Device.Process('com.example.myapp');
  CalendarView := p.RootLayout('').Layout('layoutTop').Layout('layout2').CalendarView('calendarView1');
  
  // Swipe the device to change dates
  Mobile.Device.Swipe(200, 200, 200, 300);
  
  // Touch the date by coordinates
  CalendarView.Touch(110, 90);
  
  // Get the calendar date
  CalendarDate := CalendarView.wDate;
  
  // Post the date to the log
  Log.Message(CalendarDate);
end;

C++Script, C#Script

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

  // Obtain the CalendarView object
  var p = Mobile["Device"]["Process"]("com.example.myapp");
  var Calendar = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout2")["CalendarView"]("calendarView1");
  
  // Swipe the device to change dates
  Mobile["Device"].Swipe(200, 200, 200, 300);
  
  // Touch the date by coordinates
  Calendar["Touch"](110, 90);
  
  // Get the calendar date
  var CalendarDate = CalendarView["wDate"];
  
  // Post the date to the log
  Log["Message"](CalendarDate);
}

The required coordinates will differ depending on the style of the calendar and the mobile device.
Simulating Actions From Keyword Tests

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

See Also

Working With Android Calendar Controls
Checking a Calendar's Date Range
wDate Property (Mobile Controls)
Touch Action (Mobile Objects)

Highlight search results