From f5bc054099e0a03c62c88f1d467c5b4b5b615101 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 8 Jul 2024 14:35:22 +0100 Subject: [PATCH] Fix issue with attaching screenshots --- init_helpers.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/init_helpers.py b/init_helpers.py index 02e88d032..d4d2c1cc7 100644 --- a/init_helpers.py +++ b/init_helpers.py @@ -5,6 +5,7 @@ import pytest from playwright.sync_api import sync_playwright import allure +import logging playwright_helper_instance = None api_helper_instance = None @@ -59,12 +60,21 @@ def load_config_from_env(): return config def attach_screenshot(filename): + logging.basicConfig(level=logging.DEBUG) if config["browser"] == "mobile": filename = config["browser"].upper() + "_" + config["device"] + "_" + get_browser_version() + "_" + filename + "_" else: filename = config["browser"].upper() + "_" + get_browser_version() + "_" + filename + "_" - screenshot = capture_screenshot(filename) - allure.attach.file(screenshot, name=f"{filename}", attachment_type=allure.attachment_type.PNG) + + os.makedirs(os.path.dirname(filename), exist_ok=True) + logging.debug(f"Filename: {filename}") + + try: + screenshot = capture_screenshot(filename) + logging.debug(f"Screenshot saved at: {screenshot}") + allure.attach.file(screenshot, name=f"{filename}", attachment_type=allure.attachment_type.PNG) + except Exception as e: + logging.error(f"Failed to capture screenshot: {e}") config = load_config_from_env()