Index: suite_leahi/shared/scripts/configuration/utility.py =================================================================== diff -u -re2c906a7b5fde31d48d168f097fe6a5a2ab0afea -ref346661b535cbf0104cec6b7aecad9176896783 --- suite_leahi/shared/scripts/configuration/utility.py (.../utility.py) (revision e2c906a7b5fde31d48d168f097fe6a5a2ab0afea) +++ suite_leahi/shared/scripts/configuration/utility.py (.../utility.py) (revision ef346661b535cbf0104cec6b7aecad9176896783) @@ -1,5 +1,12 @@ import squish import test +import object +import names +from squish import * +from leahi_dialin.ui import utils +from builtins import int as pyInt +from datetime import datetime + def get_object_from_names(names_dict, error_message = "Missing object", timeout_ms = 200): """ @@ -11,4 +18,120 @@ return squish.waitForObject(names_dict, timeout_ms) except LookupError: test.fail("ERROR : " + error_message) - return None + return None + +def setObjectText(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 select_different_dropdown(object,type,whichTypeIndex): + type_combo_box = 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 = get_object_from_names(setObjectText(obj = names.o_option_combo_box,text = type[whichTypeIndex]),error_message=f"Option {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,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 + squish.mousePress(value_field, squish.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...") + squish.mousePress(value_field, squish.Qt.LeftButton) + 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.") + squish.mousePress(slider,squish.Qt.LeftButton) + final_value = waitForObject(value_field_obj).value + test.verify(final_value!= value, f"{parameter} slider adjusted correctly to {final_value}") + squish.mouseRelease(slider, squish.Qt.LeftButton) + if object.exists(slider_obj): + test.log(f"Waiting for {parameter} slider to close...") + waitFor(lambda: not object.exists(slider_obj), 1000) + except LookupError as e: + test.fail(f"{parameter}: LookupError - {e}") + +def get_current_date_and_time(date_format='%Y/%b/%d - %H:%M'): + date = datetime.now() + return str(date.strftime(date_format)) \ No newline at end of file