import squish import test import object import names from squish import * from leahi_dialin.ui import utils from builtins import int as pyInt def get_object_from_names(names_dict, error_message = "Missing object", timeout_ms = 200): """ To get an object with try..except catching to prevent script errors when the object is not found on the GUI @param names_dict - the dictionary element from the names.py file (ie: names.some_variable_name_of_element) @returns the object with corresponding dictionary, otherwise "None" """ try: return squish.waitForObject(names_dict, timeout_ms) except LookupError: test.fail("ERROR : " + error_message) return None def set_Object_Text(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}")