Index: suite_leahi/shared/scripts/configuration/utility.py =================================================================== diff -u -rfb27385d1c510f6d3b433ace7e2f2e7d5dda4012 -r75e3ab588237239452761d2ec90e8b3aec6a916b --- suite_leahi/shared/scripts/configuration/utility.py (.../utility.py) (revision fb27385d1c510f6d3b433ace7e2f2e7d5dda4012) +++ suite_leahi/shared/scripts/configuration/utility.py (.../utility.py) (revision 75e3ab588237239452761d2ec90e8b3aec6a916b) @@ -7,6 +7,8 @@ from configuration import config, navigation td =TD_Messaging() +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): """ @@ -18,20 +20,45 @@ 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 setObjectText(obj, text): +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 setObjectText(text,obj): + """ + Method to set object property based on text + @param text : (string) treatment parameter text + """ obj["text"] = text - return obj - + 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: @@ -166,3 +193,88 @@ + +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,1000) + test.log(f"Opening slider for {parameter}...") + squish.mousePress(value_field, squish.Qt.LeftButton) + 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 click_left_until_off(object_name): + """ + Method to perform the left arrow untill the value + becomes off + """ + parent_obj = waitForObject(object_name) + left_arrow = findObjectById(parent_obj, "_leftArrow") + + # Loop until the value becomes "off" + while findObject(object_name).value != 0.0: + squish.mouseClick(waitForObject(left_arrow)) + utils.waitForGUI(0.2) # Small delay to allow UI to update + + return None + +def get_object_color(names_dict, error_message = "Missing object color", timeout_ms = 2000): + """ + To get an object color 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).color.name + except LookupError: + test.fail("ERROR : " + error_message) + + return None +def get_object_source_path(names_dict, error_message = "Missing object source path", timeout_ms = 2000): + """ + To get an object source path 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).source.path + except LookupError: + return None + test.fail("ERROR : " + error_message) + +def get_object_text(names_dict, error_message = "Missing object text", timeout_ms = 2000): + """ + To get an object text string 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).text + except LookupError: + test.fail("ERROR : " + error_message) + return None \ No newline at end of file