Index: suite_leahi/shared/scripts/configuration/utility.py =================================================================== diff -u -re2c906a7b5fde31d48d168f097fe6a5a2ab0afea -r34175fa27bfee67e492c7dbdf4fef89d0b0e5c39 --- suite_leahi/shared/scripts/configuration/utility.py (.../utility.py) (revision e2c906a7b5fde31d48d168f097fe6a5a2ab0afea) +++ suite_leahi/shared/scripts/configuration/utility.py (.../utility.py) (revision 34175fa27bfee67e492c7dbdf4fef89d0b0e5c39) @@ -1,5 +1,6 @@ import squish import test +import object def get_object_from_names(names_dict, error_message = "Missing object", timeout_ms = 200): """ @@ -12,3 +13,49 @@ except LookupError: test.fail("ERROR : " + error_message) return None + +def findChildByText(parent_object, target_text): + """Recursively finds a child object by its text property.""" + for child in object.children(parent_object): + if hasattr(child, "text") and str(child.text) == target_text: + return child + found = findChildByText(child, target_text) + if found: + return found + 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: + test.fail("ERROR : " + error_message) + return None + +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