I do automated tests with pyautogui by image recognition (prints), but every time there is a new deploy, the system no longer allows prints and I have to capture them again. Any solution?
I tried to reduce the threshold:
def _find_element(self, reference_image_path: str, threshold=0.5,
timeout=Config.DEFAULT_TIMEOUT) -> tuple:
"""
Find an element on the screen using image recognition and return its coordinates.
Args:
reference_image_path (str): The path to the reference image to search for.
threshold (float, optional): The confidence threshold for image recognition.
Defaults to 0.8.
timeout (int, optional): The maximum time (in seconds) to search for the element.
Defaults to Config.DEFAULT_TIMEOUT.
Returns:
tuple: A tuple containing the X and Y coordinates of the found element.
"""
start_time = time.time()
while time.time() - start_time < timeout:
try:
coordinates = pyautogui.locateOnScreen(
reference_image_path, confidence=threshold)
x, y = pyautogui.center(coordinates)
return x, y
except:
pass #TODO
pytest.fail(
f"Unable to locate element {reference_image_path} after {timeout} seconds")