def verify_icon(image, template_res_w=1920, browser_res_w=1920, timeout=0): # pylint: disable=unused-argument """Verify page contains icon. In case you want to use this keyword you always have to have reference images. If reference image are not in default folders (images, files, downloads) then BASE_IMAGE_PATH should be defined in a robot file before using this keyword. Examples -------- .. code-block:: robotframework *** Variables *** ${BASE_IMAGE_PATH} ${CURDIR}${/}..${/}resources${/}images BASE_IMAGE_PATH should lead to the folder where all your reference icons are .. code-block:: robotframework VerifyIcon plane """ template_res_w, browser_res_w = int(template_res_w), int(browser_res_w) image_path = icon.get_full_image_path(image) x, _y = icon.image_recognition(image_path, template_res_w, browser_res_w, pyautog=False) if x == -1: raise QWebIconNotFoundError("Couldn't find the icon from the screen") return True
def is_icon(image, template_res_w=1920, browser_res_w=1920): """Check is the icon on the screen. In case you want to use this keyword you always have to have reference images. If reference image are not in default folders (images, files, downloads) then BASE_IMAGE_PATH should be defined in a robot file before using this keyword. Examples -------- .. code-block:: robotframework *** Variables *** ${BASE_IMAGE_PATH} ${CURDIR}${/}..${/}resources${/}images BASE_IMAGE_PATH should lead to the folder where all your reference icons are .. code-block:: robotframework ${status} IsIcon plane ${status} will be True or False. """ template_res_w, browser_res_w = int(template_res_w), int(browser_res_w) image_path = icon.get_full_image_path(image) x, _y = icon.image_recognition(image_path, template_res_w, browser_res_w, pyautog=False) if x == -1: return False return True
def click_icon(image, template_res_w=1920, browser_res_w=1920, timeout=0): # pylint: disable=unused-argument """Click the icon on the screen. In case you want to click icons you always have to have reference images. If reference picture are not in default folders (images, files, downloads) then BASE_IMAGE_PATH should be defined in a robot file before using this keyword Examples -------- .. code-block:: robotframework *** Variables *** ${BASE_IMAGE_PATH} ${CURDIR}${/}..${/}resources${/}images BASE_IMAGE_PATH should lead to the folder where all your reference icons are .. code-block:: robotframework ClickIcon plane """ template_res_w, browser_res_w = int(template_res_w), int(browser_res_w) image_path = icon.get_full_image_path(image) x, y = icon.image_recognition(image_path, template_res_w, browser_res_w, pyautog=True) if x == -1: raise QWebElementNotFoundError( "Couldn't find the icon from the screen") pyautogui.moveTo(x, y) pyautogui.click()
def verify_icon(image, template_res_w=None, browser_res_w=None, timeout=0): # pylint: disable=unused-argument r"""Verify page contains icon. In case you want to use this keyword you always have to have reference images. If reference image are not in default folders (images, files, downloads) then BASE_IMAGE_PATH should be defined in a robot file before using this keyword. LogMatchedIcons configuration is used to log screenshots of matched images to logs. By default matched images are not logged. Examples -------- .. code-block:: robotframework *** Variables *** ${BASE_IMAGE_PATH} ${CURDIR}${/}..${/}resources${/}images BASE_IMAGE_PATH should lead to the folder where all your reference icons are .. code-block:: robotframework SetConfig LogMatchedIcons True # Log matched image to logsß VerifyIcon plane Parameters ---------- image : str Image name with or without extension template_res_w : int Reference image resolution / width. 1920 by default and image will be scaled to most common resolutions. browser_res_w : int Browser resolution / width. None (default) indicates that QWeb will figure out current browser width. timeout : int How long we try to find the element for. Related keywords ---------------- \`CaptureIcon\`, \`ClickIcon\`, \`IsIcon\` """ if not browser_res_w: browser_res_w = util.get_browser_width() # use current resolution by default if not template_res_w: template_res_w = browser_res_w template_res_w, browser_res_w = int(template_res_w), int(browser_res_w) image_path = icon.get_full_image_path(image) x, _y = icon.image_recognition(image_path, template_res_w, browser_res_w, pyautog=False) if x == -1: raise QWebIconNotFoundError("Couldn't find the icon from the screen") return True
def click_icon(image, template_res_w=None, browser_res_w=None, timeout=0): # pylint: disable=unused-argument r"""Click the icon on the screen. In case you want to click icons you always have to have reference images. If reference picture are not in default folders (images, files, downloads) then BASE_IMAGE_PATH should be defined in a robot file before using this keyword Examples -------- .. code-block:: robotframework *** Variables *** ${BASE_IMAGE_PATH} ${CURDIR}${/}..${/}resources${/}images BASE_IMAGE_PATH should lead to the folder where all your reference icons are .. code-block:: robotframework ClickIcon plane Related keywords ---------------- \`ClickCell\`, \`ClickCheckbox\`, \`ClickElement\`, \`ClickItem\`, \`ClickList\`, \`ClickText\`, \`ClickUntil\`, \`ClickWhile\`, \`VerifyIcon\` """ if not browser_res_w: browser_res_w = util.get_monitor_width( ) # pyautogui works on whole screen # use current resolution by default if not template_res_w: template_res_w = browser_res_w template_res_w, browser_res_w = int(template_res_w), int(browser_res_w) image_path = icon.get_full_image_path(image) x, y = icon.image_recognition(image_path, template_res_w, browser_res_w, pyautog=True) if x == -1: raise QWebElementNotFoundError( "Couldn't find the icon from the screen") if CONFIG.get_value("RetinaDisplay"): x = x * 0.5 y = y * 0.5 pyautogui.moveTo(x, y) pyautogui.click(x, y)
def is_icon(image, template_res_w=None, browser_res_w=None): r"""Check is the icon on the screen. In case you want to use this keyword you always have to have reference images. If reference image are not in default folders (images, files, downloads) then BASE_IMAGE_PATH should be defined in a robot file before using this keyword. Examples -------- .. code-block:: robotframework *** Variables *** ${BASE_IMAGE_PATH} ${CURDIR}${/}..${/}resources${/}images BASE_IMAGE_PATH should lead to the folder where all your reference icons are .. code-block:: robotframework ${status} IsIcon plane ${status} will be True or False. Related keywords ---------------- \`CaptureIcon\`, \`ClickIcon\`, \`VerifyIcon\` """ if not browser_res_w: browser_res_w = util.get_browser_width() # use current resolution by default if not template_res_w: template_res_w = browser_res_w template_res_w, browser_res_w = int(template_res_w), int(browser_res_w) image_path = icon.get_full_image_path(image) x, _y = icon.image_recognition(image_path, template_res_w, browser_res_w, pyautog=False) if x == -1: return False return True