Index: suite_leahi/shared/scripts/configuration/utility.py =================================================================== diff -u -re262d0097836365a0adebc78a211d10b851bf23f -r7d316b6ea5f8bfeeea912930b6ab587ec8ad5868 --- suite_leahi/shared/scripts/configuration/utility.py (.../utility.py) (revision e262d0097836365a0adebc78a211d10b851bf23f) +++ suite_leahi/shared/scripts/configuration/utility.py (.../utility.py) (revision 7d316b6ea5f8bfeeea912930b6ab587ec8ad5868) @@ -1,5 +1,8 @@ import squish import test +import object +from squish import * + def get_object_from_names(names_dict, error_message = "Missing object", timeout_ms = 200): """ @@ -11,6 +14,157 @@ return squish.waitForObject(names_dict, timeout_ms) except LookupError: test.fail("ERROR : " + error_message) - return None + return None + +def get_bullet_object(screen_obj, num): + """ + To obtain a bullet object based on occurrence provided. + @param screen_obj: provides the container on which the bullet must be present + @param num: provides the occurrence value + @returns a real name object + """ + names.o_bullet_object["container"] = screen_obj + names.o_bullet_object["occurrence"] = num + 1 + return names.o_bullet_object +def get_text_object(screen_obj, txt): + """ + To obtain a text object based on text provided + @param screen_obj: provides the container on which the txt must be present + @returns a real name object + """ + names.o_text_object["container"] = screen_obj + names.o_text_object["text"] = txt + return names.o_text_object + +def set_parameter_type(text,obj): + """ + Method to set object property based on text + @param text : (string) treatment parameter text + """ + obj["text"] = text + return obj + +def findObjectById(parent, id): + """ + Recursively searches for a child object by its id. + Returns the found object or None if not found. + """ + if str(parent.id) == id: + return parent + + for child in object.children(parent): + found = findObjectById(child, id) + if found: + return found + + return None +def set_value_based_on_target(obj, target_value): + """ + obj: dictionary containing object paths + Example: + { + "value_obj": ":mainTreatmentScreen.PressureText", + "left_arrow": ":mainTreatmentScreen.LeftArrow", + "right_arrow": ":mainTreatmentScreen.RightArrow" + } + + target_value: integer or string number, e.g. 220 + """ + target_value = target_value + + # Wait for all objects + parent_obj = squish.waitForObjectExists(obj) + # change range as per your screen count + + left_arrow = findObjectById(parent_obj, "_leftArrow") + right_arrow =findObjectById(parent_obj, "_rightArrow") + + # Read current value (supports invisible text too) + try: + current_value = round(float(findObject(obj).value),1) + except LookupError: + current_value = float(findObject(obj).property("value")) + + # Determine direction + while current_value != float(target_value): + if current_value < float(target_value): + squish.mouseClick(squish.waitForObject(right_arrow)) + + elif current_value > float(target_value): + squish.mouseClick(squish.waitForObject(left_arrow)) + # Update current value after click + try: + current_value = round(float(findObject(obj).value),1) + except Exception: + current_value = float(findObject(obj).property("value")) + + test.log(f"Updated value: {current_value}") + + test.log(f"✅ Target value reached: {current_value}") + +def custom_object_for_combo_box(text): + """ + Method to set custom object property for export option + @param text : (string) parameter text + """ + names.o_option_combo_box["text"] = text + return names.o_option_combo_box + +def select_different_dropdown(object,type,whichTypeIndex): + type_combo_box = utility.get_object_from_names(object, error_message="Combo box object is missing") + if type_combo_box is not None: + squish.mouseClick(squish.waitForObjectExists(object)) + + type_option = utility.get_object_from_names(custom_object_for_combo_box(type[whichTypeIndex]),error_message=f"Option {DIALYZER_TYPE[whichTypeIndex]} object is missing",timeout_ms=5000) + if type_option is not None: + squish.mouseClick(type_option) + return True + return False # default return if not successful + +def set_value_with_slider(value_field_obj, slider_obj): + """ + Opens the slider and moves it gradually to the target value (step of 10). + Uses controlled arrow key input for fine adjustment. + """ + + try: + value_field = waitForObject(value_field_obj) + test.log(f"Opening slider for {parameter}...") + + # Try right-click first + mousePress(value_field, Qt.LeftButton) + utils.waitForGUI(0.2) + value = value_field.value + + # If not visible, try left long-press + if not object.exists(slider_obj): + test.log(f"{parameter}: Slider not opened by left-click, trying long left-press...") + mousePress(value_field, Qt.LeftButton) + snooze(1) + if not object.exists(slider_obj): + test.fail(f"{parameter}: Slider did not appear.") + + slider = waitForObject(slider_obj) + test.log(f"{parameter}: Slider appeared successfully.") + mousePress(slider,Qt.LeftButton) + final_value = waitForObject(value_field_obj).value + test.verify(final_value!= value, f"{parameter} slider adjusted correctly to {final_value}") + mouseRelease(slider, Qt.LeftButton) + utils.waitForGUI(0.2) + if object.exists(slider_obj): + test.log(f"Waiting for {parameter} slider to close...") + waitFor(lambda: not object.exists(slider_obj), 1000) + utils.waitForGUI(0.2) + except LookupError as e: + test.fail(f"{parameter}: LookupError - {e}") + +def click_left_until_off(object_name): + parent_obj = waitForObject(object_name) + left_arrow = utility.findObjectById(object,parent_obj, "_leftArrow") + + # Loop until the value becomes "off" + while findObject(object_name).value != 0.0: + mouseClick(waitForObject(left_arrow)) + utils.waitForGUI(0.2) # Small delay to allow UI to update \ No newline at end of file Index: suite_leahi/tst_create_treatment/test.py =================================================================== diff -u -r2cb969d7088c56bf8ff6384159f08c92b535bbf6 -r7d316b6ea5f8bfeeea912930b6ab587ec8ad5868 --- suite_leahi/tst_create_treatment/test.py (.../test.py) (revision 2cb969d7088c56bf8ff6384159f08c92b535bbf6) +++ suite_leahi/tst_create_treatment/test.py (.../test.py) (revision 7d316b6ea5f8bfeeea912930b6ab587ec8ad5868) @@ -121,74 +121,35 @@ VITALS = ["OFF","5","10","15","20","30","60"] BICARBONATE = ["Sodium Bicarbonate"] -def get_bullet_object(screen_obj, num): - """ - To obtain a bullet object based on occurrence provided. - @param screen_obj: provides the container on which the bullet must be present - @param num: provides the occurrence value - @returns a real name object - """ - names.o_bullet_object["container"] = screen_obj - names.o_bullet_object["occurrence"] = num + 1 - return names.o_bullet_object -def get_text_object(screen_obj, txt): - """ - To obtain a text object based on text provided - @param screen_obj: provides the container on which the txt must be present - @returns a real name object - """ - names.o_text_object["container"] = screen_obj - names.o_text_object["text"] = txt - return names.o_text_object - def verify_page_step_indicator(screen_obj, treatment_step, treatment_screens): """ Method to verify the Page Step indicators [the object on top of the screen which indicates the steps passed, current, remained] @param treatment_step : (int) indicates the Current treatment step """ test.startSection("verification of page step indicators") for page in range(len(treatment_screens)): - bullet_children = object.children(squish.waitForObjectExists(get_bullet_object(screen_obj, page))) + bullet_children = object.children(squish.waitForObjectExists(utility.get_bullet_object(screen_obj, page))) bullet_circle_color = bullet_children[0].color.name bullet_border_color = bullet_children[0].border.color.name - step_title = squish.waitForObjectExists(get_text_object(screen_obj, treatment_screens[page])) + step_title = squish.waitForObjectExists(utility.get_text_object(screen_obj, treatment_screens[page])) #To verify the step indicators of the completed treatment screens if page < treatment_step: - test.verify(squish.waitForObjectExists(get_bullet_object(screen_obj, page)).complete) - test.verify(not squish.waitForObjectExists(get_bullet_object(screen_obj, page)).current) + test.verify(squish.waitForObjectExists(utility.get_bullet_object(screen_obj, page)).complete) + test.verify(not squish.waitForObjectExists(utility.get_bullet_object(screen_obj, page)).current) test.compare(bullet_circle_color, COMPLETE_COLOR) test.compare(bullet_border_color, COMPLETE_COLOR) test.compare(step_title.color.name, ENABLED_COLOR) #To verify the step indicators of the current treatment screen elif page == treatment_step: test.compare(bullet_border_color, COMPLETE_COLOR) - # test.compare(step_title.color.name, ENABLED_COLOR) #To verify the step indicators of the remaining treatment screens else: - test.verify(not squish.waitForObjectExists(get_bullet_object(screen_obj, page)).complete) + test.verify(not squish.waitForObjectExists(utility.get_bullet_object(screen_obj, page)).complete) test.compare(bullet_circle_color, CURRENT_COLOR) test.endSection() -def custom_object_for_combo_box(text): - """ - Method to set custom object property for export option - @param text : (string) parameter text - """ - names.o_option_combo_box["text"] = text - return names.o_option_combo_box - -def select_different_dropdown(object,type,whichTypeIndex): - type_combo_box = utility.get_object_from_names(object, error_message="Combo box object is missing") - if type_combo_box is not None: - mouseClick(waitForObjectExists(object)) - - type_option = utility.get_object_from_names(custom_object_for_combo_box(type[whichTypeIndex]),error_message=f"Option {DIALYZER_TYPE[whichTypeIndex]} object is missing",timeout_ms=5000) - if type_option is not None: - mouseClick(type_option) - return True - return False # default return if not successful - + def verify_create_custom_treatment_parameter(): """ Method to set create custom treatment slider value based on slider buffer @@ -199,82 +160,82 @@ test.startSection("Verification of blood flow values") test.compare(waitForObject(names.o_PreTreatmentCreate_bloodFlowRate_LabelUnitContainer).text, BLOOD_FLOW_RATE, "Parameter should be -> "+str(BLOOD_FLOW_RATE)) for blood_flow_rate in CREATE_TREATMENT_PARAMETER_RANGE[BLOOD_FLOW_RATE]: - set_value_based_on_target(names.o_PreTreatmentCreate_bloodFlowRateControl_ValueAdjuster, blood_flow_rate) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_bloodFlowRateControl_ValueAdjuster, blood_flow_rate) test.endSection() test.startSection("Verification of dialysate flow values") test.compare(waitForObject(names.o_PreTreatmentCreate_dialysateFlowRate_LabelUnitContainer).text, DIALYSATE_FLOW_RATE, "Parameter should be -> "+str(DIALYSATE_FLOW_RATE)) for dialysate_flow_rate in CREATE_TREATMENT_PARAMETER_RANGE[DIALYSATE_FLOW_RATE]: - set_value_based_on_target(names.o_PreTreatmentCreate_dialysateFlowRateControl_ValueAdjuster, dialysate_flow_rate) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_dialysateFlowRateControl_ValueAdjuster, dialysate_flow_rate) test.endSection() test.startSection("Verification of duration values") test.compare(waitForObject(names.o_PreTreatmentCreate_duration_LabelUnitContainer).text, DURATION, "Parameter should be -> "+str(DURATION)) for duration in CREATE_TREATMENT_PARAMETER_RANGE[DURATION]: - set_value_based_on_target(names.o_PreTreatmentCreate_durationControl_ValueAdjuster, duration) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_durationControl_ValueAdjuster, duration) test.endSection() test.startSection("Verification of heparin bolus volume values") test.compare(waitForObject(names.o_PreTreatmentCreate_heparinBolusVolume_LabelUnitContainer).text, HEPARIN_BOLUS_VOLUME, "Parameter should be -> "+str(HEPARIN_BOLUS_VOLUME)) mouseClick(waitForObject(names.o_PreTreatmentCreate_heparinBolusVolumeControl_ValueAdjuster)) for heparin_bolus_volume in CREATE_TREATMENT_PARAMETER_RANGE[HEPARIN_BOLUS_VOLUME]: - set_value_based_on_target(names.o_PreTreatmentCreate_heparinBolusVolumeControl_ValueAdjuster, heparin_bolus_volume) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_heparinBolusVolumeControl_ValueAdjuster, heparin_bolus_volume) test.endSection() test.startSection("Verification of heparin dispensing rate values") test.compare(waitForObject(names.o_PreTreatmentCreate_heparinDispensingRate_LabelUnitContainer).text, HEPARIN_DISPENSING_RATE, "Parameter should be -> "+str(HEPARIN_DISPENSING_RATE)) mouseClick(waitForObject(names.o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster)) for heparin_dispensing_rate in CREATE_TREATMENT_PARAMETER_RANGE[HEPARIN_DISPENSING_RATE]: - set_value_based_on_target(names.o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster, heparin_dispensing_rate) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster, heparin_dispensing_rate) test.endSection() test.startSection("Verification of heparin stop time values") #1. Change Duration -> Verify Heparin Stop Time "active" property is set to off - set_value_based_on_target(names.o_PreTreatmentCreate_durationControl_ValueAdjuster, 60) - set_value_based_on_target(names.o_PreTreatmentCreate_heparinBolusVolumeControl_ValueAdjuster, 0.4) - set_value_based_on_target(names.o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster, 0.3) - set_value_based_on_target(names.o_PreTreatmentCreate_heparinStopTimeControl_ValueAdjuster, 60) - set_value_based_on_target(names.o_PreTreatmentCreate_durationControl_ValueAdjuster, 75) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_durationControl_ValueAdjuster, 60) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_heparinBolusVolumeControl_ValueAdjuster, 0.4) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster, 0.3) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_heparinStopTimeControl_ValueAdjuster, 60) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_durationControl_ValueAdjuster, 75) heprain_Stop_time = waitForObject(names.o_PreTreatmentCreate_heparinStopTimeControl_ValueAdjuster) test.compare(heprain_Stop_time.isActive,False, "Heprain stop time active property is set to False") # 2. Change Heparin Dispensising Rate from 0.2 to OFF -> Verify Heparing Stop Time is set to OFF - set_value_based_on_target(names.o_PreTreatmentCreate_durationControl_ValueAdjuster, 60) - set_value_based_on_target(names.o_PreTreatmentCreate_heparinBolusVolumeControl_ValueAdjuster, 0.4) - set_value_based_on_target(names.o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster, 0.3) - set_value_based_on_target(names.o_PreTreatmentCreate_heparinStopTimeControl_ValueAdjuster, 60) - click_left_until_off(names.o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_durationControl_ValueAdjuster, 60) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_heparinBolusVolumeControl_ValueAdjuster, 0.4) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster, 0.3) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_heparinStopTimeControl_ValueAdjuster, 60) + utility.click_left_until_off(names.o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster) test.compare(waitForObjectExists(names.o_PreTreatmentCreate_heparinStopTime_OFF_Text).text,"OFF") # # 3. Change Heparin Dispensising Rate from OFF to 0.2 -> Verify Heparin Stop Time "active" property is set to off - set_value_based_on_target(o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster, 0.2) + utility.set_value_based_on_target(o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster, 0.2) test.compare(waitForObjectExists(names.o_PreTreatmentCreate_heparinStopTime_OFF_Text).text,"-- --") # # 4. When Duration is set to a value -> Verify the max Heparin Stop Time is the Duration value that is set - set_value_based_on_target(names.o_PreTreatmentCreate_durationControl_ValueAdjuster, 90) - set_value_based_on_target(names.o_PreTreatmentCreate_heparinStopTimeControl_ValueAdjuster, 90) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_durationControl_ValueAdjuster, 90) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_heparinStopTimeControl_ValueAdjuster, 90) test.compare(waitForObjectExists(names.o_PreTreatmentCreate_heparinStopTimeControl_ValueAdjuster).value,90.0) obj = waitForObject(names.o_PreTreatmentCreate_heparinStopTimeControl_ValueAdjuster) - right_arrow =findObjectById(obj ,"_rightArrow") + right_arrow =utility.findObjectById(object,obj ,"_rightArrow") test.compare(not right_arrow.enabled, True, "Right arrow is disabled in Heparin stop time field") - set_value_based_on_target(names.o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster, "0.2") - set_value_based_on_target(names.o_PreTreatmentCreate_durationControl_ValueAdjuster, "480") + utility.set_value_based_on_target(names.o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster, "0.2") + utility.set_value_based_on_target(names.o_PreTreatmentCreate_durationControl_ValueAdjuster, "480") test.compare(waitForObject(names.o_PreTreatmentCreate_heparinStopTime_LabelUnitContainer).text, HEPARIN_STOP_TIME, "Parameter should be -> "+str(HEPARIN_STOP_TIME)) for heparin_stop_time in CREATE_TREATMENT_PARAMETER_RANGE[HEPARIN_STOP_TIME]: - set_value_based_on_target(names.o_PreTreatmentCreate_heparinStopTimeControl_ValueAdjuster, heparin_stop_time) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_heparinStopTimeControl_ValueAdjuster, heparin_stop_time) test.endSection() test.startSection("Verification of Dialysate Temperature") test.compare(waitForObject(names.o_PreTreatmentCreate_dialysateTemperature_LabelUnitContainer).text,DIALYSATE_TEMPERATURE , "Parameter should be -> "+str(DIALYSATE_TEMPERATURE)) for dialysate_temperature in CREATE_TREATMENT_PARAMETER_RANGE[DIALYSATE_TEMPERATURE]: - set_value_based_on_target(names.o_PreTreatmentCreate_dialysateTemperatureControl_ValueAdjuster,dialysate_temperature) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_dialysateTemperatureControl_ValueAdjuster,dialysate_temperature) test.endSection() test.startSection("Verification of saline bolus values") test.compare(waitForObject(names.o_PreTreatmentCreate_salineBolusVolume_LabelUnitContainer).text, SALINE_BOLUS_VOLUME, "Parameter should be -> "+str(SALINE_BOLUS_VOLUME)) for saline_bolus in CREATE_TREATMENT_PARAMETER_RANGE[SALINE_BOLUS_VOLUME]: - set_value_based_on_target(names.o_PreTreatmentCreate_salineBolusVolumeControl_ValueAdjuster, saline_bolus) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_salineBolusVolumeControl_ValueAdjuster, saline_bolus) test.endSection() test.startSection("Verification of acid concentrate type") @@ -284,36 +245,36 @@ mouseClick(waitForObject(names.o_potassium_leftArrow_IconButton)) mouseClick(waitForObject(names.o_calcium_leftArrow_IconButton)) mouseClick(waitForObject(names.o_saveButton_TouchRect)) - select_different_dropdown(names.o_PreTreatmentCreate_acidConcentrateComboBox_BaseComboBox,ACID_CONCENTRATE,0) + utility.select_different_dropdowndropdown(names.o_PreTreatmentCreate_acidConcentrateComboBox_BaseComboBox,ACID_CONCENTRATE,0) test.compare(waitForObject(names.o_PreTreatmentCreate_acidConcentrateComboBox_BaseComboBox).currentText, ACID_CONCENTRATE[0], "Acid concentrate value should be :"+str(ACID_CONCENTRATE[0])) - select_different_dropdown(names.o_PreTreatmentCreate_acidConcentrateComboBox_BaseComboBox,ACID_CONCENTRATE,1) + utility.select_different_dropdown(names.o_PreTreatmentCreate_acidConcentrateComboBox_BaseComboBox,ACID_CONCENTRATE,1) test.compare(waitForObject(names.o_PreTreatmentCreate_acidConcentrateComboBox_BaseComboBox).currentText, ACID_CONCENTRATE[1], "Acid concentrate value should be :"+str(ACID_CONCENTRATE[1])) - select_different_dropdown(names.o_PreTreatmentCreate_acidConcentrateComboBox_BaseComboBox,ACID_CONCENTRATE,2) + utility.select_different_dropdown(names.o_PreTreatmentCreate_acidConcentrateComboBox_BaseComboBox,ACID_CONCENTRATE,2) test.compare(waitForObject(names.o_PreTreatmentCreate_acidConcentrateComboBox_BaseComboBox).currentText, ACID_CONCENTRATE[2], "Acid concentrate value should be :"+str(ACID_CONCENTRATE[2])) - select_different_dropdown(names.o_PreTreatmentCreate_acidConcentrateComboBox_BaseComboBox,ACID_CONCENTRATE,3) + utility.select_different_dropdown(names.o_PreTreatmentCreate_acidConcentrateComboBox_BaseComboBox,ACID_CONCENTRATE,3) test.compare(waitForObject(names.o_PreTreatmentCreate_acidConcentrateComboBox_BaseComboBox).currentText, ACID_CONCENTRATE[3], "Acid concentrate value should be :"+str(ACID_CONCENTRATE[3])) test.endSection() test.startSection("Verification of dialyzer type") test.compare(waitForObject(names.o_PreTreatmentCreate_dialysateTemperature_LabelUnitContainer).text, DIALYZER_TYPE_TITLE, "Parameter should be -> "+str(DIALYZER_TYPE_TITLE)) - select_different_dropdown(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox,DIALYZER_TYPE,0) + utility.select_different_dropdown(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox,DIALYZER_TYPE,0) test.compare(waitForObject(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox).currentText, DIALYZER_TYPE[0], "Dialyzer type value should be :"+str(DIALYZER_TYPE[0])) - select_different_dropdown(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox,DIALYZER_TYPE,1) + utility.select_different_dropdown(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox,DIALYZER_TYPE,1) test.compare(waitForObject(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox).currentText, DIALYZER_TYPE[1], "Dialyzer type value should be :"+str(DIALYZER_TYPE[1])) - select_different_dropdown(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox,DIALYZER_TYPE,2) + utility.select_different_dropdown(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox,DIALYZER_TYPE,2) test.compare(waitForObject(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox).currentText, DIALYZER_TYPE[2], "Dialyzer type value should be :"+str(DIALYZER_TYPE[2])) - select_different_dropdown(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox,DIALYZER_TYPE,3) + utility.select_different_dropdown(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox,DIALYZER_TYPE,3) test.compare(waitForObject(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox).currentText, DIALYZER_TYPE[3], "Dialyzer type value should be :"+str(DIALYZER_TYPE[3])) - select_different_dropdown(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox,DIALYZER_TYPE,4) + utility.select_different_dropdown(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox,DIALYZER_TYPE,4) test.compare(waitForObject(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox).currentText, DIALYZER_TYPE[4], "Dialyzer type value should be :"+str(DIALYZER_TYPE[4])) - select_different_dropdown(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox,DIALYZER_TYPE,5) + utility.select_different_dropdown(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox,DIALYZER_TYPE,5) test.compare(waitForObject(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox).currentText, DIALYZER_TYPE[5], "Dialyzer type value should be :"+str(DIALYZER_TYPE[5])) - select_different_dropdown(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox,DIALYZER_TYPE,6) + utility.select_different_dropdown(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox,DIALYZER_TYPE,6) test.compare(waitForObject(names.o_PreTreatmentCreate_dialyzerTypeComboBox_BaseComboBox).currentText, DIALYZER_TYPE[6], "Dialyzer type value should be :"+str(DIALYZER_TYPE[6])) test.endSection() - select_different_dropdown(names.o_PreTreatment_vitalsCombobox_BaseCombobox,VITALS,2) + utility.select_different_dropdown(names.o_PreTreatment_vitalsCombobox_BaseCombobox,VITALS,2) select_different_dropdown(names.o_PreTreatmentCreate_bicarbonateConcentrateComboBox_BaseComboBox,BICARBONATE,0) test.verify(waitForObjectExists(names.o_PreTreatmentCreate_qrCode_Image), "QR Code is visible") #Verify all the parameters are populated @@ -365,27 +326,27 @@ test.startSection("Verification of blood flow values") test.compare(waitForObject(names.o_PreTreatmentCreate_bloodFlowRate_LabelUnitContainer).text, BLOOD_FLOW_RATE, "Parameter should be -> "+str(BLOOD_FLOW_RATE)) for blood_flow_rate in CREATE_TREATMENT_PARAMETER[BLOOD_FLOW_RATE]: - set_value_based_on_target(names.o_PreTreatmentCreate_bloodFlowRateControl_ValueAdjuster, blood_flow_rate) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_bloodFlowRateControl_ValueAdjuster, blood_flow_rate) test.endSection() test.startSection("Verification of dialysate flow values") test.compare(waitForObject(names.o_PreTreatmentCreate_dialysateFlowRate_LabelUnitContainer).text, DIALYSATE_FLOW_RATE, "Parameter should be -> "+str(DIALYSATE_FLOW_RATE)) for dialysate_flow_rate in CREATE_TREATMENT_PARAMETER[DIALYSATE_FLOW_RATE]: - set_value_based_on_target(names.o_PreTreatmentCreate_dialysateFlowRateControl_ValueAdjuster, dialysate_flow_rate) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_dialysateFlowRateControl_ValueAdjuster, dialysate_flow_rate) test.endSection() test.startSection("Verification of duration values") test.compare(waitForObject(names.o_PreTreatmentCreate_duration_LabelUnitContainer).text, DURATION, "Parameter should be -> "+str(DURATION)) for duration in CREATE_TREATMENT_PARAMETER[DURATION]: - set_value_based_on_target(names.o_PreTreatmentCreate_durationControl_ValueAdjuster, duration) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_durationControl_ValueAdjuster, duration) test.endSection() test.startSection("Verification of heparin bolus volume values") test.compare(waitForObject(names.o_PreTreatmentCreate_heparinBolusVolume_LabelUnitContainer).text, HEPARIN_BOLUS_VOLUME, "Parameter should be -> "+str(HEPARIN_BOLUS_VOLUME)) mouseClick(waitForObject(names.o_PreTreatmentCreate_heparinBolusVolumeControl_ValueAdjuster)) test.compare(OFF_TEXT, waitForObject(names.o_PreTreatmentCreate_heparinBolusVolume_Off_Text).text, "OFF text should be enabled") for heparin_bolus_volume in CREATE_TREATMENT_PARAMETER[HEPARIN_BOLUS_VOLUME]: - set_value_based_on_target(names.o_PreTreatmentCreate_heparinBolusVolumeControl_ValueAdjuster, heparin_bolus_volume) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_heparinBolusVolumeControl_ValueAdjuster, heparin_bolus_volume) test.endSection() @@ -394,27 +355,27 @@ mouseClick(waitForObject(names.o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster)) test.compare(OFF_TEXT, waitForObject(names.o_PreTreatmentCreate_heparinDispensingRateControl_OffText).text, "OFF text should be enabled") for heparin_dispensing_rate in CREATE_TREATMENT_PARAMETER[HEPARIN_DISPENSING_RATE]: - set_value_based_on_target(names.o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster, heparin_dispensing_rate) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster, heparin_dispensing_rate) test.endSection() test.startSection("Verification of heparin stop time values") - set_value_based_on_target(names.o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster, "0.2") - set_value_based_on_target(names.o_PreTreatmentCreate_durationControl_ValueAdjuster, "480") + utility.set_value_based_on_target(names.o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster, "0.2") + utility.set_value_based_on_target(names.o_PreTreatmentCreate_durationControl_ValueAdjuster, "480") test.compare(waitForObject(names.o_PreTreatmentCreate_heparinStopTime_LabelUnitContainer).text, HEPARIN_STOP_TIME, "Parameter should be -> "+str(HEPARIN_STOP_TIME)) for heparin_stop_time in CREATE_TREATMENT_PARAMETER[HEPARIN_STOP_TIME]: - set_value_based_on_target(names.o_PreTreatmentCreate_heparinStopTimeControl_ValueAdjuster, heparin_stop_time) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_heparinStopTimeControl_ValueAdjuster, heparin_stop_time) test.endSection() test.startSection("Verification of Dialysate Temperature") test.compare(waitForObject(names.o_PreTreatmentCreate_dialysateTemperature_LabelUnitContainer).text,DIALYSATE_TEMPERATURE , "Parameter should be -> "+str(DIALYSATE_TEMPERATURE)) for dialysate_temperature in CREATE_TREATMENT_PARAMETER_RANGE[DIALYSATE_TEMPERATURE]: - set_value_based_on_target(names.o_PreTreatmentCreate_dialysateTemperatureControl_ValueAdjuster,dialysate_temperature) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_dialysateTemperatureControl_ValueAdjuster,dialysate_temperature) test.endSection() test.startSection("Verification of saline bolus values") test.compare(waitForObject(names.o_PreTreatmentCreate_salineBolusVolume_LabelUnitContainer).text, SALINE_BOLUS_VOLUME, "Parameter should be -> "+str(SALINE_BOLUS_VOLUME)) for saline_bolus in CREATE_TREATMENT_PARAMETER[SALINE_BOLUS_VOLUME]: - set_value_based_on_target(names.o_PreTreatmentCreate_salineBolusVolumeControl_ValueAdjuster, saline_bolus) + utility.set_value_based_on_target(names.o_PreTreatmentCreate_salineBolusVolumeControl_ValueAdjuster, saline_bolus) test.endSection() td.td_operation_mode(TDOpModes.MODE_PRET.value, 0) @@ -452,91 +413,8 @@ button = waitForObjectExists(names.o_PreTreatmentButton) test.verify(not button.enabled, "Validate that the button is disabled") test.endSection() - - -def findObjectById(parent, id): - """ - Recursively searches for a child object by its id. - Returns the found object or None if not found. - """ - if str(parent.id) == id: - return parent - - for child in object.children(parent): - found = findObjectById(child, id) - if found: - return found - - return None + -def click_left_until_off(object_name): - parent_obj = waitForObject(object_name) - left_arrow = findObjectById(parent_obj, "_leftArrow") - - # Loop until the value becomes "off" - while findObject(object_name).value != 0.0: - mouseClick(waitForObject(left_arrow)) - utils.waitForGUI(0.2) # Small delay to allow UI to update - -def set_value_based_on_target(obj, target_value): - """ - obj: dictionary containing object paths - Example: - { - "value_obj": ":mainTreatmentScreen.PressureText", - "left_arrow": ":mainTreatmentScreen.LeftArrow", - "right_arrow": ":mainTreatmentScreen.RightArrow" - } - - target_value: integer or string number, e.g. 220 - """ - target_value = target_value - - # Wait for all objects - parent_obj = waitForObjectExists(obj) - # change range as per your screen count - - left_arrow = findObjectById(parent_obj, "_leftArrow") - right_arrow =findObjectById(parent_obj, "_rightArrow") - - # Read current value (supports invisible text too) - try: - current_value = round(float(findObject(obj).value),1) - except LookupError: - current_value = float(findObject(obj).property("value")) - - # Determine direction - while current_value != float(target_value): - if current_value < float(target_value): - mouseClick(waitForObject(right_arrow)) - - elif current_value > float(target_value): - mouseClick(waitForObject(left_arrow)) - # Update current value after click - try: - current_value = round(float(findObject(obj).value),1) - except Exception: - current_value = float(findObject(obj).property("value")) - - test.log(f"Updated value: {current_value}") - - test.log(f"✅ Target value reached: {current_value}") - -def check_arrow_status(obj): - parent_obj = waitForObjectExists(obj) - left_arrow = findObjectById(parent_obj, "_leftArrow") - right_arrow =findObjectById(parent_obj, "_rightArrow") - test.verify(not left_arrow.enabled, "left arrow button is disabled") - test.verify(not right_arrow.enabled, "Right arrow button is disabled") - -def set_parameter_type(text,obj): - """ - Method to set object property based on text - @param text : (string) treatment parameter text - """ - obj["text"] = text - return obj - def verify_custom_treatment_record_rejected(): """ Method to verify custom treatment record, if confirmation rejected @@ -568,65 +446,26 @@ for expected_treatment_title,object in zip(CREATE_TREATMENT_PARAMETERS,CREATE_TREATEMENT_OBJ): - parameter_object = set_parameter_type(text = expected_treatment_title,obj =object) + parameter_object = utility.set_parameter_type(text = expected_treatment_title,obj =object) parameter_text = waitForObject(parameter_object) parameter_text_color = parameter_text.border.color.name test.compare(COLOR_CODES, parameter_text_color, "parameter color should be ' \red for' " + expected_treatment_title +" , if the confirmation get rejected !") test.endSection() -def set_value_with_slider(value_field_obj, slider_obj,parameter): - """ - Opens the slider and moves it gradually to the target value (step of 10). - Uses controlled arrow key input for fine adjustment. - """ - - try: - value_field = waitForObject(value_field_obj) - test.log(f"Opening slider for {parameter}...") - - # Try right-click first - mousePress(value_field, Qt.LeftButton) - utils.waitForGUI(0.2) - value = value_field.value - - # If not visible, try left long-press - if not object.exists(slider_obj): - test.log(f"{parameter}: Slider not opened by left-click, trying long left-press...") - mousePress(value_field, Qt.LeftButton) - snooze(1) - if not object.exists(slider_obj): - test.fail(f"{parameter}: Slider did not appear.") - - slider = waitForObject(slider_obj) - test.log(f"{parameter}: Slider appeared successfully.") - mousePress(slider,Qt.LeftButton) - final_value = waitForObject(value_field_obj).value - test.verify(final_value!= value, f"{parameter} slider adjusted correctly to {final_value}") - mouseRelease(slider, Qt.LeftButton) - utils.waitForGUI(0.2) - if object.exists(slider_obj): - test.log(f"Waiting for {parameter} slider to close...") - waitFor(lambda: not object.exists(slider_obj), 1000) - utils.waitForGUI(0.2) - except LookupError as e: - test.fail(f"{parameter}: LookupError - {e}") - - def verify_custom_treatment_slider(): test.startSection("Verifying slider functionality of custom treatment") td.td_operation_mode(TDOpModes.MODE_STAN.value) td.td_operation_mode(TDOpModes.MODE_TPAR.value, 0 ) utils.waitForGUI(5) - set_value_with_slider(names.o_PreTreatmentCreate_bloodFlowRateControl_ValueAdjuster,names.o_PreTreatmentCreate_bloodFlowRate_slider_Slider,BLOOD_FLOW_RATE) - set_value_with_slider(names.o_PreTreatmentCreate_dialysateFlowRateControl_ValueAdjuster,names.o_PreTreatmentCreate_dialysateFlowRate_slider_Slider,DIALYSATE_FLOW_RATE) - set_value_with_slider(names.o_PreTreatmentCreate_durationControl_ValueAdjuster,names.o_PreTreatmentCreate_duration_slider_Slider,DURATION) - set_value_with_slider(names.o_PreTreatmentCreate_heparinBolusVolumeControl_ValueAdjuster,names.o_PreTreatmentCreate_heprainBolusVolume_slider_Slider,HEPARIN_BOLUS_VOLUME) - set_value_with_slider(names.o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster,names.o_PreTreatmentCreate_heprainDispensingRate_slider_Slider,HEPARIN_DISPENSING_RATE) - set_value_with_slider(names.o_PreTreatmentCreate_heparinStopTimeControl_ValueAdjuster,names.o_PreTreatmentCreate_heprainStopTime_slider_Slider,HEPARIN_STOP_TIME) - set_value_with_slider(names.o_PreTreatmentCreate_dialysateTemperatureControl_ValueAdjuster,names.o_PreTreatmentCreate_dialysateTemperature_slider_Slider,DIALYSATE_TEMPERATURE) - set_value_with_slider(names.o_PreTreatmentCreate_salineBolusVolumeControl_ValueAdjuster,names.o_PreTreatmentCreate_salineBolusVolume_slider_Slider,SALINE_BOLUS_VOLUME) - # set_value_with_slider(names.o_PreTreatmentCreate_bpMeasurementIntervalControl_ValueAdjuster,names.o_PreTreatmentCreate_bpMeasurementInterval_slider_Slider,BLOOD_PRESSURE_MEASUREMENT_INTERVAL) + utility.set_value_with_slider(names.o_PreTreatmentCreate_bloodFlowRateControl_ValueAdjuster,names.o_PreTreatmentCreate_bloodFlowRate_slider_Slider,BLOOD_FLOW_RATE) + utility.set_value_with_slider(names.o_PreTreatmentCreate_dialysateFlowRateControl_ValueAdjuster,names.o_PreTreatmentCreate_dialysateFlowRate_slider_Slider,DIALYSATE_FLOW_RATE) + utility.set_value_with_slider(names.o_PreTreatmentCreate_durationControl_ValueAdjuster,names.o_PreTreatmentCreate_duration_slider_Slider,DURATION) + utility.set_value_with_slider(names.o_PreTreatmentCreate_heparinBolusVolumeControl_ValueAdjuster,names.o_PreTreatmentCreate_heprainBolusVolume_slider_Slider,HEPARIN_BOLUS_VOLUME) + utility.set_value_with_slider(names.o_PreTreatmentCreate_heparinDispensingRateControl_ValueAdjuster,names.o_PreTreatmentCreate_heprainDispensingRate_slider_Slider,HEPARIN_DISPENSING_RATE) + utility.set_value_with_slider(names.o_PreTreatmentCreate_heparinStopTimeControl_ValueAdjuster,names.o_PreTreatmentCreate_heprainStopTime_slider_Slider,HEPARIN_STOP_TIME) + utility.set_value_with_slider(names.o_PreTreatmentCreate_dialysateTemperatureControl_ValueAdjuster,names.o_PreTreatmentCreate_dialysateTemperature_slider_Slider,DIALYSATE_TEMPERATURE) + utility.set_value_with_slider(names.o_PreTreatmentCreate_salineBolusVolumeControl_ValueAdjuster,names.o_PreTreatmentCreate_salineBolusVolume_slider_Slider,SALINE_BOLUS_VOLUME) test.endSection() def main():