# -*- 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 import calendar from configuration import config, utility from dialin.ui.hd_simulator import HDSimulator from dialin.common.hd_defs import HDOpModes from dialin.ui import utils from configuration.config import SERVICE_CONF_LOCATION, ENABLED from calendar import isleap hd_simulator = HDSimulator() SERVICES_TITLE_TEXT = "Please Enter The Service Password" 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 DATE_AND_TIME_MESSAGE = "AdjustHDDateTime" INCORRECT_PASSWORD = "abcd" INCORRECT_PASSWORD_MSG = "Incorrect service password" SERVICE_SCREEN_OPTIONS = ["Information", "Volume And Brightness", "Wi-Fi", "Bluetooth Cuff", "Dialysate Generator Settings", "Set Date And Time", "Set Language", "Software Update", "Factory Reset", "Calibration ", ] EMPTY_INPUT_FIELD = "" def settings_text_obj(text): names.o_settings_home_text_obj["text"] = text return names.o_settings_home_text_obj def services_screen_text_obj(text): names.o_services_screen_text_obj["text"] = text return names.o_services_screen_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_settings_screen(): """ Method to navigate to "Settings" screen """ test.startSection("Navigating to 'Device Settings' screen") hd_simulator.cmd_send_hd_operation_mode(op_mode=HDOpModes.MODE_STAN.value, sub_mode=HDOpModes.MODE_FAUL.value) utils.waitForGUI(1) mouseClick(waitForObjectExists(names.o_settings_Text)) device_settings_text = waitForObjectExists(settings_text_obj(config.DEVICE_SETTINGS_TEXT)) test.compare(device_settings_text.text, config.DEVICE_SETTINGS_TEXT, "{} screen is displayed".format(config.DEVICE_SETTINGS_TEXT)) test.endSection() def verify_incorrect_password_msg(): """ Method to verify the message displayed upon entering wrong password """ test.startSection("Verifying the functionalities with Incorrect password") test.log("Clicking on password entry field") utils.waitForGUI(0.3) mouseClick(waitForObjectExists(names.o_password_text_field)) utility.enter_keyboard_numeric_value(entry=str(INCORRECT_PASSWORD)) mouseClick(waitForObjectExists(names.o_show_password)) test.log("Verifying the entered password") password = str((waitForObjectExists(names.o_password_text_field)).text) test.compare(password, INCORRECT_PASSWORD, "Entered password should be {}".format(str(INCORRECT_PASSWORD))) mouseClick(waitForObjectExists(services_screen_text_obj(config.CONFIRM_TEXT))) incorrect_password_text = waitForObjectExists(settings_text_obj(INCORRECT_PASSWORD_MSG)) test.compare(incorrect_password_text.text, INCORRECT_PASSWORD_MSG, "{} message should display upon entering wrong password".format(INCORRECT_PASSWORD_MSG)) test.endSection() def navigate_to_services_password_screen_and_enter_password(): """ Method to navigate to services screen and verify the "Please Enter The Service Password" title is displayed and enter password, verify the password and click on confirm button """ test.startSection("Navigating to 'services password' screen and enter password") mouseClick(waitForObjectExists(settings_text_obj(config.SERIVCES_TITLE))) services_password_title = waitForObjectExists(services_screen_text_obj(SERVICES_TITLE_TEXT)) test.compare(services_password_title.text, SERVICES_TITLE_TEXT, "{} should display once user is navigated to services password screen".format(SERVICES_TITLE_TEXT)) utils.waitForGUI(0.5) verify_incorrect_password_msg() utils.waitForGUI(0.5) mouseClick(waitForObjectExists(settings_text_obj(config.SERIVCES_TITLE))) utils.waitForGUI(0.5) test.log("Clicking on password entry field") utils.waitForGUI(0.5) mouseClick(waitForObjectExists(names.o_switch_keyboard_to_keypad)) mouseClick(waitForObjectExists(names.o_password_text_field)) with open(SERVICE_CONF_LOCATION, "r") as file: lines = file.readlines() for index, line in enumerate(lines): if "Service Password" in line: services_password = lines[index+1][:-1] break else: continue utility.enter_keyboard_numeric_value(entry=str(services_password)) mouseClick(waitForObjectExists(names.o_show_password)) test.log("Verifying the entered password") password = str((waitForObjectExists(names.o_password_text_field)).text) test.compare(password, str(services_password), "Entered password should be {}".format(str(services_password))) mouseClick(waitForObjectExists(services_screen_text_obj(config.CONFIRM_TEXT))) utils.waitForGUI(0.5) test.log("Verifying the 'Export' button") test.compare(str(waitForObjectExists(settings_text_obj(config.EXPORT_TEXT)).text), config.EXPORT_TEXT,"'Export' button text should be {}".format(config.EXPORT_TEXT)) utils.waitForGUI(0.5) mouseClick(waitForObjectExists(settings_text_obj(config.EXPORT_TEXT))) test.compare(waitForObjectExists(settings_text_obj(config.EXPORT_TEXT)).enabled , True, "'Export' button should be enabled") test.log("Verifying the 'Shutdown' button enabled") test.compare(str(waitForObjectExists(names.o_shutdown_text).text), config.SHUTDOWN_TEXT,"'SHUTDOWN' button text should be {}".format(config.SHUTDOWN_TEXT)) test.compare(waitForObjectExists(names.o_shutdown_text).enabled , True, "'SHUTDOWN' button should be enabled") for option in SERVICE_SCREEN_OPTIONS: option_text = waitForObjectExists(settings_text_obj(option)) test.compare(option_text.text, option, "{} should be available under services screen".format(option)) 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(settings_text_obj(SET_DATE_AND_TIME_TEXT))) set_date_and_time_title = waitForObjectExists(date_time_screen_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_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) 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): """ Method to verify the valid and invalid color of entry of date and time @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 """ test.startSection("Verify the color of {} 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 (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==1 or entry==3 or entry==5 or entry==7 or entry==8 or entry==10 or entry==12): day_upper_limit = DAY_UPPER_LIMIT test.log("Number of days is " + str(day_upper_limit)) elif(entry==4 or entry==6 or entry==9 or entry==11): day_upper_limit = DAY_UPPER_LIMIT - 1 test.log("Number of days is " + str(day_upper_limit)) if(entry==2 and isleap(date_time_parameter is YEAR_TEXT)): day_upper_limit = DAY_UPPER_LIMIT - 2 test.log("Number of days is " + str(day_upper_limit)) elif(entry==2): day_upper_limit = DAY_UPPER_LIMIT - 3 test.log("Number of days is " + str(day_upper_limit)) 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 """ 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) else: if not(object.exists(date_time_screen_text_obj(text=config.CONFIRM_TEXT))): test.passes("Confirm button is not available") def main(): utils.tstStart(__file__) startApplication(config.AUT_NAME) navigate_to_settings_screen() navigate_to_services_password_screen_and_enter_password() navigate_to_set_date_and_time() 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=DATE_AND_TIME_MESSAGE) utils.tstDone()