def log_screenshot(filename='screenshot_{}.png'): r"""Log screenshot to Robot Framework log. Examples -------- .. code-block:: robotframework LogScreenshot ${file}= LogScreenshot # returns full path to saved image file Parameters ---------- filename : str Filename where the screenshot is saved. Returns ------- filepath : full path to saved screenshot Related keywords ---------------- \`LogPage\` """ filepath = None if CONFIG["LogScreenshot"]: screenshot_type = CONFIG["ScreenshotType"] if screenshot_type == 'screenshot': filepath = screenshot.save_screenshot(filename) screenshot.log_screenshot_file(filepath) elif screenshot_type == 'html': screenshot.log_html() elif screenshot_type == 'all': filepath = screenshot.save_screenshot(filename) screenshot.log_screenshot_file(filepath) screenshot.log_html() else: raise ValueError( 'Unknown screenshot type: {}'.format(screenshot_type)) else: logger.info( 'Screenshots have been disabled with the SetConfig keyword.') return filepath
def image_recognition(image_path, template_res_w, browser_res_w, pyautog): """Return icon's coordinates.""" image_rec = QIcon() frame.wait_page_loaded() screenshot_path = save_screenshot("screenshot.png", pyautog=pyautog) x, y = image_rec.image_location(needle=image_path, haystack=screenshot_path, template_res_w=template_res_w, device_res_w=browser_res_w) return x, y
def capture_icon(locator, folder='screenshots', filename='screenshot_{}.png', timeout=0, **kwargs): # pylint: disable=unused-argument r"""Take a screenshot of an element. Examples -------- .. code-block:: robotframework ${some_xpath}= //*[@value\="Button3"] CaptureIcon ${some_xpath} CaptureIcon Button3 CaptureIcon Button3 custom_screenshot_name_123.png CaptureIcon Button3 custom_screenshot_name_123.png C:/custom/folder/path Parameters ---------- locator : str Locator for the element we are trying to capture, XPath or attribute value. When using XPaths, the equal sign "=" must be escaped with a "\\". folder : str Optional folder path. Default value is the screenshots folder. filename : str Optional filename. timeout : int How long we try to find the element for. Related keywords ---------------- \`ClickIcon\`, \`IsIcon\`, \`VerifyIcon\` """ if util.xpath_validator(locator): web_element = element.get_unique_element_by_xpath(locator) else: web_element = text.get_item_using_anchor(locator, anchor='1', **kwargs) img = Image.open(io.BytesIO(web_element.screenshot_as_png)) filepath = os.path.join(screenshot.save_screenshot(filename, folder)) logger.info('Screenshot path: {}'.format(filepath.replace('\\', '/')), also_console=True) img.save(filepath) screenshot.log_screenshot_file(filepath)