# -*- coding: utf-8 -*-" ## # Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. # copyright # THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, # IN PART OR IN WHOLE, # WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. # # file tst_settings_date_and_time # date 05/15/2022 # author Papiya Mandal # author Amrita Debnath import builtins import names from configuration import config, utility from dialin.ui.hd_simulator import HDSimulator from dialin.common.hd_defs import HDOpModes, HDStandbyStates from dialin.ui import utils from calendar import isleap hd_simulator = HDSimulator() SET_DATE_AND_TIME_TEXT = "Set Date And Time" TIME_TITLE = "Time (HH:MM)" DATE_TITLE_TEXT = "Date (MM/DD/YYYY)" HOUR_TEXT = "Hour" MINUTE_TEXT = "Minute" DAY_TEXT = "Day" MONTH_TEXT = "Month" YEAR_TEXT = "Year" HOUR_UPPER_LIMIT = 23 HOUR_LOWER_LIMIT = 0 MINUTE_LOWER_LIMIT = 0 MINUTE_UPPER_LIMIT = 59 DAY_UPPER_LIMIT = 31 DAY_LOWER_LIMIT = 1 MONTH_UPPER_LIMIT = 12 MONTH_LOWER_LIMIT = 1 YEAR_UPPER_LIMIT = 2100 YEAR_LOWER_LIMIT = 1970 CONFIRMATION_MESSAGE = "Setting date and time ..." HD_DATE_AND_TIME_MESSAGE = "AdjustHDDateTime" DG_DATE_AND_TIME_MESSAGE = "AdjustDGDateTime" SERVICE_SCREEN_OPTIONS = ["Information", "Volume And Brightness", "Wi-Fi", "Bluetooth Cuff", "DG Cleaning", "Set Date And Time", "Export Logs" ] EMPTY_INPUT_FIELD = "" def service_text_obj(text): names.o_service_home_text_obj["text"] = text return names.o_service_home_text_obj def settings_text_obj(text): names.o_set_date_and_time_text_obj["text"] = text return names.o_set_date_and_time_text_obj def date_time_screen_text_obj(text): names.o_settings_date_and_time_text["text"] = text return names.o_settings_date_and_time_text def navigate_to_service_screen(): """ Method to navigate to "Service" screen """ test.startSection("Navigating to 'Service' screen") hd_simulator.cmd_send_hd_operation_mode(op_mode=HDOpModes.MODE_SERV.value, sub_mode=HDStandbyStates.STANDBY_START_STATE.value) utils.waitForGUI(0.5) service_screen_text = waitForObjectExists(service_text_obj(config.SERVICE_SCREEN_TITLE_TEXT)) test.compare(service_screen_text.text, config.SERVICE_SCREEN_TITLE_TEXT, "{} screen is displayed".format(config.SERVICE_SCREEN_TITLE_TEXT)) test.endSection() def navigate_to_set_date_and_time(): """ Method to navigate to set date and time screen and verify its title 'Set Date And Time' """ test.startSection("Navigating 'Set Date And Time' screen") utils.waitForGUI(0.5) mouseClick(waitForObjectExists(names.o_SettingsHome_mouseArea_MouseArea_2_set_date_time)) set_date_and_time_title = waitForObjectExists(settings_text_obj(SET_DATE_AND_TIME_TEXT)) test.compare(set_date_and_time_title.text, SET_DATE_AND_TIME_TEXT, "{} should be displayed when user is navigated to 'Set Date And Time' screen".format(SET_DATE_AND_TIME_TEXT)) test.endSection() def verify_back_btn(): """ Method to verify the back button and click """ test.startSection("Verify the 'BACK' button") test.compare(str(waitForObjectExists(settings_text_obj(config.BACK_TEXT)).text), config.BACK_TEXT,"'BACK' button text should be {}".format(config.BACK_TEXT)) utils.waitForGUI(0.1) test.compare(waitForObjectExists(settings_text_obj(config.BACK_TEXT)).enabled , True, "'BACK' button should be enabled") mouseClick(waitForObjectExists(names.o_SettingsDateTime_mouseArea_MouseArea_2)) utils.waitForGUI(0.5) mouseClick(waitForObjectExists(names.o_SettingsHome_mouseArea_MouseArea_2_set_date_time)) test.endSection() def verify_entered_date_and_time(hour, min, day, month, year, valid_parameter_passed): """ Method to enter date and time and verify the valid and invalid entries @param hour - (str) Hour @param min - (str) Minute @param day - (str) Day @param month - (str) Month @param year - (str) Year @param valid_paramter_passed - (bool) True/False whether hour/minute/day/month/year is valid """ test.startSection("Enter date and time and verify the valid and invalid entries") date_time_column = waitForObjectExists(names.o_date_time_container) date_time_column_children = object.children(date_time_column) ITEM_0_TIME_ROW = 0 ITEM_1_DATE_ROW = 1 TITLE_OBJECT_ITEM_NUMBER_0 = 0 time_row = date_time_column_children[ITEM_0_TIME_ROW] date_row = date_time_column_children[ITEM_1_DATE_ROW] time_row_children = object.children(time_row) date_row_children = object.children(date_row) time_title_text = time_row_children[TITLE_OBJECT_ITEM_NUMBER_0] date_title_text = date_row_children[TITLE_OBJECT_ITEM_NUMBER_0] test.log("Verifying time title text") test.compare(time_title_text.text, TIME_TITLE, "{} should be the time title text".format(TIME_TITLE)) test.log("Verifying date title text") test.compare(date_title_text.text, DATE_TITLE_TEXT, "{} should be the date title text".format(DATE_TITLE_TEXT)) hour_parent = time_row_children[1] hour_parent_children = object.children(hour_parent) INPUT_FIELD_INDEX = 1 hour_input_field = hour_parent_children[INPUT_FIELD_INDEX] minute_parent = time_row_children[-1] minute_parent_children = object.children(minute_parent) minute_input_field = minute_parent_children[ INPUT_FIELD_INDEX] test.log("Entering hour") utils.waitForGUI(0.5) mouseClick(hour_input_field) utility.erase_entered_value(hour_input_field) utility.enter_keypad_value(hour) verify_valid_and_invalid_entry_and_its_color(entry=hour, date_time_parameter=HOUR_TEXT, input_field=hour_input_field) test.log("Entering minute") mouseClick(minute_input_field) utility.erase_entered_value(minute_input_field) utility.enter_keypad_value(min) verify_valid_and_invalid_entry_and_its_color(entry=min, date_time_parameter=MINUTE_TEXT, input_field=minute_input_field) MONTH_PARENT_INDEX = 1 DAY_PARENT_INDEX = 3 YEAR_PARENT_INDEX = -1 month_parent = date_row_children[MONTH_PARENT_INDEX] month_children = object.children(month_parent) month_input_field = month_children[INPUT_FIELD_INDEX] day_parent = date_row_children[DAY_PARENT_INDEX] day_children = object.children(day_parent) day_input_field = day_children[INPUT_FIELD_INDEX] year_parent = date_row_children[YEAR_PARENT_INDEX] year_children = object.children(year_parent) year_input_field = year_children[INPUT_FIELD_INDEX] test.log("Entering Month") mouseClick(month_input_field) utility.erase_entered_value(month_input_field) utility.enter_keypad_value(month) verify_valid_and_invalid_entry_and_its_color(entry=month, date_time_parameter=MONTH_TEXT, input_field=month_input_field) test.log("Entering Day") mouseClick(day_input_field) utility.erase_entered_value(day_input_field) utility.enter_keypad_value(day) verify_valid_and_invalid_entry_and_its_color(entry=day, date_time_parameter=DAY_TEXT, input_field=day_input_field, month=month) test.log("Entering Year") mouseClick(year_input_field) utility.erase_entered_value(year_input_field) utility.enter_keypad_value(year) verify_valid_and_invalid_entry_and_its_color(entry=year, date_time_parameter=YEAR_TEXT, input_field=year_input_field) verify_confirm_btn(valid_parameter_passed) test.endSection() def verify_valid_and_invalid_entry_and_its_color(entry, date_time_parameter, input_field, month=None): """ Method to verify the valid and invalid entry of date and time and its color @param entry: (int) user user entered value @param date_time_parameter - (str) parameter name under which user is entering value (hour/minute/day/month/year) @param input_field - (obj) object of input field @param month - (int) value is passed when entry to entry passed to determine the number of days in month """ test.startSection("Verify the valid and invalid entry of date and time and its color {} value {}".format(date_time_parameter, entry)) actual_value = str(input_field.text) actual_value = builtins.int(actual_value) input_field_color = input_field.color.name entry = builtins.int(entry) if date_time_parameter is HOUR_TEXT: if (entry < HOUR_LOWER_LIMIT) or (entry > HOUR_UPPER_LIMIT): test.compare(actual_value, entry, "{} value {} should be equal to {}".format(date_time_parameter, actual_value, entry)) test.compare(input_field_color, config.OUT_OF_RANGE_COLOR, "Hour value {} is out of range, hour value should be in range of {} and {}".format(entry, HOUR_LOWER_LIMIT, HOUR_UPPER_LIMIT)) elif (entry >= HOUR_LOWER_LIMIT) and (entry <= HOUR_UPPER_LIMIT): test.xcompare(actual_value, EMPTY_INPUT_FIELD, "{} value {} should be equal to '{}'".format(date_time_parameter, actual_value, EMPTY_INPUT_FIELD)) test.compare(input_field_color, config.IN_RANGE_COLOR, "Hour value {} is in range of {} and {}".format(entry, HOUR_LOWER_LIMIT, HOUR_UPPER_LIMIT)) elif date_time_parameter is MINUTE_TEXT: if (entry < MINUTE_LOWER_LIMIT) or (entry > MINUTE_UPPER_LIMIT): test.compare(actual_value, entry, "{} value {} should be equal to {}".format(date_time_parameter, actual_value, entry)) test.compare(input_field_color, config.OUT_OF_RANGE_COLOR, "Minute value {} is out of range, minute value should be in range of {} and {}".format(entry, MINUTE_LOWER_LIMIT, MINUTE_UPPER_LIMIT)) elif (entry >= MINUTE_LOWER_LIMIT) and (entry <= MINUTE_UPPER_LIMIT): test.xcompare(actual_value, EMPTY_INPUT_FIELD, "{} value {} should be equal to '{}'".format(date_time_parameter, actual_value, EMPTY_INPUT_FIELD)) test.compare(input_field_color, config.IN_RANGE_COLOR, "Minute value {} is in range of {} and {}".format(entry, MINUTE_LOWER_LIMIT, MINUTE_UPPER_LIMIT)) elif date_time_parameter is DAY_TEXT: if(month == 4 or month == 6 or month == 9 or month == 11): day_upper_limit = DAY_UPPER_LIMIT - 1 elif(month == 2 and isleap(date_time_parameter is YEAR_TEXT)): day_upper_limit = DAY_UPPER_LIMIT - 2 elif(month == 2): day_upper_limit = DAY_UPPER_LIMIT - 3 else: day_upper_limit = DAY_UPPER_LIMIT if (entry < DAY_LOWER_LIMIT) or (entry > day_upper_limit): test.compare(actual_value, entry, "{} value {} should be equal to {}".format(date_time_parameter, actual_value, entry)) test.compare(input_field_color, config.OUT_OF_RANGE_COLOR, "Day value {} is out of range, Day value should be in range of {} and {}".format(entry, DAY_LOWER_LIMIT, day_upper_limit)) elif (entry >= DAY_LOWER_LIMIT) and (entry <= day_upper_limit): test.xcompare(actual_value, EMPTY_INPUT_FIELD, "{} value {} should be equal to '{}'".format(date_time_parameter, actual_value, EMPTY_INPUT_FIELD)) test.compare(input_field_color,config.IN_RANGE_COLOR, "Day value {} is in range of {} and {}".format(entry, DAY_LOWER_LIMIT, day_upper_limit)) elif date_time_parameter is MONTH_TEXT: if (entry < MONTH_LOWER_LIMIT) or (entry > MONTH_UPPER_LIMIT): test.compare(actual_value, entry, "{} value {} should be equal to {}".format(date_time_parameter, actual_value, entry)) test.compare(input_field_color, config.OUT_OF_RANGE_COLOR, "Month value {} is out of range, Month value should be in range of {} and {}".format(entry, MONTH_LOWER_LIMIT, MONTH_UPPER_LIMIT)) elif (entry >= MONTH_LOWER_LIMIT) and (entry <= MONTH_UPPER_LIMIT): test.xcompare(actual_value, EMPTY_INPUT_FIELD, "{} value {} should be equal to '{}'".format(date_time_parameter, actual_value, EMPTY_INPUT_FIELD)) test.compare(input_field_color, config.IN_RANGE_COLOR, "Month value {} is in range of {} and {}".format(entry, MONTH_LOWER_LIMIT, MONTH_UPPER_LIMIT)) elif date_time_parameter is YEAR_TEXT: if (entry < YEAR_LOWER_LIMIT) or (entry > YEAR_UPPER_LIMIT): test.compare(actual_value, entry, "{} value {} should be equal to {}".format(date_time_parameter, actual_value, entry)) test.compare(input_field_color, config.OUT_OF_RANGE_COLOR, "Year value {} is out of range, Year value should be in range of {} and {}".format(entry, YEAR_LOWER_LIMIT, YEAR_UPPER_LIMIT)) elif (entry >= YEAR_LOWER_LIMIT) and (entry <= YEAR_UPPER_LIMIT): test.xcompare(actual_value, EMPTY_INPUT_FIELD, "{} value {} should be equal to '{}'".format(date_time_parameter, actual_value, EMPTY_INPUT_FIELD)) test.compare(input_field_color, config.IN_RANGE_COLOR, "Year value {} is in range of {} and {}".format(entry, YEAR_LOWER_LIMIT, YEAR_UPPER_LIMIT)) test.endSection() def verify_confirm_btn(valid_parameter_passed): """ Method to verify the status of confirm button and click on confirm button @param valid_paramter_passed - (bool) True/False whether hour/minute/day/month/year is valid """ test.startSection("Verify the status of confirm button and click on confirm button") if valid_parameter_passed is config.VALID: if object.exists(date_time_screen_text_obj(text=config.CONFIRM_TEXT)): confirm_btn = waitForObjectExists(date_time_screen_text_obj(text=config.CONFIRM_TEXT)) test.compare(confirm_btn.enabled, config.ENABLED, "Confirm Button should be enabled") mouseClick(confirm_btn) confirm_msg = waitForObjectExists(settings_text_obj(CONFIRMATION_MESSAGE)) test.compare(confirm_msg.visible, config.VISIBLE, "{} message should be displayed".format(CONFIRMATION_MESSAGE)) else: if not(object.exists(date_time_screen_text_obj(text=config.CONFIRM_TEXT))): test.passes("Confirm button is not available") test.endSection() def main(): utils.tstStart(__file__) startApplication(config.AUT_NAME+ " -l") navigate_to_service_screen() navigate_to_set_date_and_time() verify_back_btn() verify_entered_date_and_time(hour="24", min="33", day="1", month="3", year="2022", valid_parameter_passed=config.INVALID) verify_entered_date_and_time(hour="00", min="60", day="29", month="2", year="2020", valid_parameter_passed=config.INVALID) verify_entered_date_and_time(hour="13", min="33", day="32", month="2", year="2022", valid_parameter_passed=config.INVALID) verify_entered_date_and_time(hour="13", min="33", day="4", month="13", year="2022", valid_parameter_passed=config.INVALID) verify_entered_date_and_time(hour="22", min="33", day="22", month="12", year="2101", valid_parameter_passed=config.INVALID) verify_entered_date_and_time(hour="22", min="33", day="22", month="11", year="1969", valid_parameter_passed=config.INVALID) verify_entered_date_and_time(hour="23", min="12", day="7", month="8", year="1977", valid_parameter_passed=config.VALID) utility.get_current_log_details(message_text=HD_DATE_AND_TIME_MESSAGE) utility.get_current_log_details(message_text=DG_DATE_AND_TIME_MESSAGE) utils.tstDone()