From 9d28d8284bb526ce5a9b722666280027781130b2 Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Fri, 14 Jul 2023 15:39:01 +0200 Subject: [PATCH 1/8] fixes to be able to run logs without root permission --- .gitignore | 2 +- tests/selenium_tests.py | 2 +- testui/support/appium_driver.py | 30 ++++++++++-------------------- testui/support/helpers.py | 4 +--- testui/support/logger.py | 25 +++++++------------------ testui/support/parallel.py | 12 +++++------- testui/support/testui_driver.py | 13 +++---------- testui/support/testui_images.py | 6 +----- 8 files changed, 29 insertions(+), 65 deletions(-) diff --git a/.gitignore b/.gitignore index a27713e..0d1e73d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # Created by https://www.toptal.com/developers/gitignore/api/python,visualstudiocode,pycharm,macos # Edit at https://www.toptal.com/developers/gitignore?templates=python,visualstudiocode,pycharm,macos -appium_logs +logs ### macOS ### # General .DS_Store diff --git a/tests/selenium_tests.py b/tests/selenium_tests.py index bad63d3..821d69f 100644 --- a/tests/selenium_tests.py +++ b/tests/selenium_tests.py @@ -31,7 +31,7 @@ def test_template_matching(self, selenium_driver: TestUIDriver): "https://github.com/testdevlab/Py-TestUI#image-recognition" ) selenium_driver.find_image_match( - "resources/comp.png", 0.9, True, image_match="image.png" + "resources/comp.png", 0.9, True, image_match="./logs/image.png" ) selenium_driver.raise_errors() diff --git a/testui/support/appium_driver.py b/testui/support/appium_driver.py index 371dcef..a7c1f0c 100644 --- a/testui/support/appium_driver.py +++ b/testui/support/appium_driver.py @@ -411,19 +411,14 @@ def __local_run(url, desired_caps, use_port, udid, log_file): if udid is None: desired_caps = __set_android_device(desired_caps, device) logger.log(f'setting device for automation: {desired_caps["udid"]}') - root_dir = ( - os.path.dirname( - os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - ) - + "/" - ) - Path(root_dir + "appium_logs").mkdir(parents=True, exist_ok=True) + root_dir = "./logs" + Path(os.path.join(root_dir, "appium_logs")).mkdir(parents=True, exist_ok=True) file_path: str if log_file == "appium-stdout.log": - file = f"appium_logs/testui-{udid}-" + log_file + file = os.path.join(root_dir, f"testui-{udid}-" + log_file) else: - file = f"appium_logs/{log_file}" - with open(root_dir + file, "wb") as out: + file = os.path.join(root_dir, log_file) + with open(file, "wb") as out: process = subprocess.Popen( ["appium", "-p", port.__str__(), "-bp", bport.__str__()], stdout=out, @@ -465,19 +460,14 @@ def __local_run_ios(url, desired_caps, use_port, udid, log_file): os.getenv("PYTEST_XDIST_WORKER").split("w")[1] ) logger.log(f"running: appium -p {port.__str__()}") - root_dir = ( - os.path.dirname( - os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - ) - + "/" - ) - Path(root_dir + "appium_logs").mkdir(parents=True, exist_ok=True) + root_dir = "./logs" + Path(os.path.join(root_dir, "appium_logs")).mkdir(parents=True, exist_ok=True) file_path: str if log_file == "appium-stdout.log": - file = f"appium_logs/testui-{udid}-" + log_file + file = os.path.join(root_dir, f"testui-{udid}-" + log_file) else: - file = f"appium_logs/{log_file}" - with open(root_dir + file, "wb") as out: + file = os.path.join(root_dir, log_file) + with open(file, "wb") as out: process = subprocess.Popen( ["appium", "-p", port.__str__()], stdout=out, diff --git a/testui/support/helpers.py b/testui/support/helpers.py index d649e8b..7f3c102 100644 --- a/testui/support/helpers.py +++ b/testui/support/helpers.py @@ -10,8 +10,6 @@ def error_with_traceback(exception): ) line: str for line in traceback.extract_stack().format(): - if line.__contains__(root_dir) and not line.__contains__( - "traceback.extract_stack()" - ): + if root_dir in line and not "traceback.extract_stack()" in line: exception += logger.bcolors.FAIL + line + logger.bcolors.ENDC return exception diff --git a/testui/support/logger.py b/testui/support/logger.py index cc18fce..7bce70d 100644 --- a/testui/support/logger.py +++ b/testui/support/logger.py @@ -2,6 +2,7 @@ from datetime import datetime from pathlib import Path +ROOT_DIR = "./logs" class bcolors: """ @@ -145,19 +146,13 @@ def __file_log(log_file="stdout.log"): :param log_file: String :return: String """ - root_dir = ( - os.path.dirname( - os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - ) - + "/" - ) - Path(root_dir + "appium_logs").mkdir(parents=True, exist_ok=True) + Path(ROOT_DIR).mkdir(parents=True, exist_ok=True) file_name: str if log_file == "stdout.log": - file_name = f"appium_logs/TEST_UI-{log_file}" + file_name = os.path.join(ROOT_DIR, f"TEST_UI-{log_file}") else: - file_name = f"appium_logs/{log_file}" - return root_dir + file_name + file_name = os.path.join(ROOT_DIR, log_file) + return file_name def __file_tests(log_file="report_cases.txt"): @@ -166,11 +161,5 @@ def __file_tests(log_file="report_cases.txt"): :param log_file: String :return: String """ - root_dir = ( - os.path.dirname( - os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - ) - + "/" - ) - Path(root_dir + "appium_logs").mkdir(parents=True, exist_ok=True) - return root_dir + log_file + Path(ROOT_DIR).mkdir(parents=True, exist_ok=True) + return os.path.join(ROOT_DIR, log_file) diff --git a/testui/support/parallel.py b/testui/support/parallel.py index dd01d01..81a44ae 100644 --- a/testui/support/parallel.py +++ b/testui/support/parallel.py @@ -89,14 +89,12 @@ def remove_logs(): """ Will remove the logs from the previous execution. """ - root_dir = os.path.dirname( - os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - ) + root_dir = "./logs" i = 0 try: - for filename in os.listdir(root_dir + "/report_screenshots"): + for filename in os.listdir(os.path.join(root_dir, "report_screenshots")): file_path = os.path.join( - root_dir + "/report_screenshots/", filename + os.path.join(root_dir, "report_screenshots"), filename ) os.remove(file_path) if i == 0: @@ -106,8 +104,8 @@ def remove_logs(): pass i = 0 try: - for filename in os.listdir(root_dir + "/appium_logs"): - file_path = os.path.join(root_dir + "/appium_logs/", filename) + for filename in os.listdir(root_dir): + file_path = os.path.join(root_dir, filename) os.remove(file_path) if i == 0: logger.log("Cleaning appium_logs folder...") diff --git a/testui/support/testui_driver.py b/testui/support/testui_driver.py index 1c0adb7..47e95e7 100644 --- a/testui/support/testui_driver.py +++ b/testui/support/testui_driver.py @@ -270,7 +270,7 @@ def get_dimensions(self): image_name = f"{self.device_udid}{current_time}.png" path_s = self.save_screenshot(image_name) dimensions = ImageRecognition( - original=path_s + original=path_s, path="" ).image_original_size() logger.log(f"Deleting screenshot: {path_s}") self.__delete_screenshot(path_s) @@ -299,9 +299,7 @@ def save_screenshot(self, image_name=""): root_dir = config.screenshot_path if not config.screenshot_path: - root_dir = path.dirname( - path.dirname(path.dirname(path.abspath(__file__))) - ) + root_dir = "./logs" root_dir = path.join(root_dir, "report_screenshots") Path(root_dir).mkdir(parents=True, exist_ok=True) @@ -328,9 +326,6 @@ def __delete_screenshot(cls, image_name): :param image_name: :return: """ - root_dir = os.path.dirname( - os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - ) os.remove(image_name) def get_driver(self) -> WebDriver: @@ -464,9 +459,7 @@ def stop_recording_and_compare( current_time = now.strftime("%Y-%m-%d%H%M%S") video_name = f"{self.device_udid}{current_time}.mp4" self.stop_recording_screen(video_name) - root_dir = os.path.dirname( - os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - ) + root_dir = "./logs" if self.__configuration.screenshot_path != "": root_dir = self.__configuration.screenshot_path found = ImageRecognition( diff --git a/testui/support/testui_images.py b/testui/support/testui_images.py index ef5a561..de4e415 100644 --- a/testui/support/testui_images.py +++ b/testui/support/testui_images.py @@ -370,16 +370,12 @@ class ImageRecognition: """ def __init__( - self, original: str, comparison="", threshold=0.9, device_name="Device", path="" + self, original: str, comparison="", threshold=0.9, device_name="Device", path="./logs" ): self.__original = original self.__comparison = comparison self.__threshold = threshold self.__device_name = device_name - if path == "": - path = os.path.dirname( - os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - ) self.__path = path def compare(self, image_match="", max_scale=2.0, min_scale=0.3): From 2f1b6b7fe79389ca2c7a897df0da59037e15103a Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Fri, 14 Jul 2023 16:08:20 +0200 Subject: [PATCH 2/8] fix path for appium logs --- testui/support/appium_driver.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/testui/support/appium_driver.py b/testui/support/appium_driver.py index a7c1f0c..9286d0a 100644 --- a/testui/support/appium_driver.py +++ b/testui/support/appium_driver.py @@ -411,8 +411,8 @@ def __local_run(url, desired_caps, use_port, udid, log_file): if udid is None: desired_caps = __set_android_device(desired_caps, device) logger.log(f'setting device for automation: {desired_caps["udid"]}') - root_dir = "./logs" - Path(os.path.join(root_dir, "appium_logs")).mkdir(parents=True, exist_ok=True) + root_dir = os.path.join("./logs", "appium_logs") + Path(root_dir).mkdir(parents=True, exist_ok=True) file_path: str if log_file == "appium-stdout.log": file = os.path.join(root_dir, f"testui-{udid}-" + log_file) @@ -425,7 +425,7 @@ def __local_run(url, desired_caps, use_port, udid, log_file): stderr=subprocess.STDOUT, ) atexit.register(process.kill) - file_path = root_dir + file + file_path = file while True: sleep(0.5) out = open(file_path) @@ -460,8 +460,8 @@ def __local_run_ios(url, desired_caps, use_port, udid, log_file): os.getenv("PYTEST_XDIST_WORKER").split("w")[1] ) logger.log(f"running: appium -p {port.__str__()}") - root_dir = "./logs" - Path(os.path.join(root_dir, "appium_logs")).mkdir(parents=True, exist_ok=True) + root_dir = os.path.join("./logs", "appium_logs") + Path(root_dir).mkdir(parents=True, exist_ok=True) file_path: str if log_file == "appium-stdout.log": file = os.path.join(root_dir, f"testui-{udid}-" + log_file) @@ -474,7 +474,7 @@ def __local_run_ios(url, desired_caps, use_port, udid, log_file): stderr=subprocess.STDOUT, ) atexit.register(process.kill) - file_path = root_dir + file + file_path = file if udid is None: desired_caps = __set_ios_device(desired_caps, device) while True: From bb87b3fdbaa1c98221356813316a2f2b6bf28522 Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Fri, 14 Jul 2023 16:17:22 +0200 Subject: [PATCH 3/8] appium logs to be appended to each device --- testui/support/appium_driver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testui/support/appium_driver.py b/testui/support/appium_driver.py index 9286d0a..cbac18a 100644 --- a/testui/support/appium_driver.py +++ b/testui/support/appium_driver.py @@ -418,7 +418,7 @@ def __local_run(url, desired_caps, use_port, udid, log_file): file = os.path.join(root_dir, f"testui-{udid}-" + log_file) else: file = os.path.join(root_dir, log_file) - with open(file, "wb") as out: + with open(file, "a+") as out: process = subprocess.Popen( ["appium", "-p", port.__str__(), "-bp", bport.__str__()], stdout=out, @@ -467,7 +467,7 @@ def __local_run_ios(url, desired_caps, use_port, udid, log_file): file = os.path.join(root_dir, f"testui-{udid}-" + log_file) else: file = os.path.join(root_dir, log_file) - with open(file, "wb") as out: + with open(file, "a+") as out: process = subprocess.Popen( ["appium", "-p", port.__str__()], stdout=out, From cb6a3ca089aa7be18c1ea7c96dbfa73b69859f09 Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Fri, 14 Jul 2023 16:25:42 +0200 Subject: [PATCH 4/8] check writing file --- testui/support/appium_driver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testui/support/appium_driver.py b/testui/support/appium_driver.py index cbac18a..77e854f 100644 --- a/testui/support/appium_driver.py +++ b/testui/support/appium_driver.py @@ -418,7 +418,7 @@ def __local_run(url, desired_caps, use_port, udid, log_file): file = os.path.join(root_dir, f"testui-{udid}-" + log_file) else: file = os.path.join(root_dir, log_file) - with open(file, "a+") as out: + with open(file, "a") as out: process = subprocess.Popen( ["appium", "-p", port.__str__(), "-bp", bport.__str__()], stdout=out, @@ -467,7 +467,7 @@ def __local_run_ios(url, desired_caps, use_port, udid, log_file): file = os.path.join(root_dir, f"testui-{udid}-" + log_file) else: file = os.path.join(root_dir, log_file) - with open(file, "a+") as out: + with open(file, "a") as out: process = subprocess.Popen( ["appium", "-p", port.__str__()], stdout=out, From fe0f583347fb903e292cc710fd2f28e7657db24f Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Fri, 14 Jul 2023 16:32:01 +0200 Subject: [PATCH 5/8] appium different logs --- testui/support/appium_driver.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/testui/support/appium_driver.py b/testui/support/appium_driver.py index 77e854f..8d43411 100644 --- a/testui/support/appium_driver.py +++ b/testui/support/appium_driver.py @@ -1,7 +1,9 @@ import atexit +import datetime import os import subprocess import threading +import time from pathlib import Path from time import sleep @@ -415,10 +417,10 @@ def __local_run(url, desired_caps, use_port, udid, log_file): Path(root_dir).mkdir(parents=True, exist_ok=True) file_path: str if log_file == "appium-stdout.log": - file = os.path.join(root_dir, f"testui-{udid}-" + log_file) + file = os.path.join(root_dir, f"testui-{udid}-{time.time()}-" + log_file) else: file = os.path.join(root_dir, log_file) - with open(file, "a") as out: + with open(file, "wb") as out: process = subprocess.Popen( ["appium", "-p", port.__str__(), "-bp", bport.__str__()], stdout=out, @@ -464,10 +466,10 @@ def __local_run_ios(url, desired_caps, use_port, udid, log_file): Path(root_dir).mkdir(parents=True, exist_ok=True) file_path: str if log_file == "appium-stdout.log": - file = os.path.join(root_dir, f"testui-{udid}-" + log_file) + file = os.path.join(root_dir, f"testui-{udid}-{time.time()}-" + log_file) else: file = os.path.join(root_dir, log_file) - with open(file, "a") as out: + with open(file, "wb") as out: process = subprocess.Popen( ["appium", "-p", port.__str__()], stdout=out, From c513ad277eecd39537e31a208f2f4f8b65cf1b37 Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Mon, 24 Jul 2023 10:02:55 +0200 Subject: [PATCH 6/8] fix comments for file_path and log_dir name --- testui/support/appium_driver.py | 22 ++++++++++------------ testui/support/parallel.py | 10 ++++++++++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/testui/support/appium_driver.py b/testui/support/appium_driver.py index 8d43411..404944d 100644 --- a/testui/support/appium_driver.py +++ b/testui/support/appium_driver.py @@ -413,21 +413,20 @@ def __local_run(url, desired_caps, use_port, udid, log_file): if udid is None: desired_caps = __set_android_device(desired_caps, device) logger.log(f'setting device for automation: {desired_caps["udid"]}') - root_dir = os.path.join("./logs", "appium_logs") - Path(root_dir).mkdir(parents=True, exist_ok=True) + log_dir = os.path.join("./logs", "appium_logs") + Path(log_dir).mkdir(parents=True, exist_ok=True) file_path: str if log_file == "appium-stdout.log": - file = os.path.join(root_dir, f"testui-{udid}-{time.time()}-" + log_file) + file_path = os.path.join(log_dir, f"testui-{udid}-{time.time()}-" + log_file) else: - file = os.path.join(root_dir, log_file) - with open(file, "wb") as out: + file_path = os.path.join(log_dir, log_file) + with open(file_path, "wb") as out: process = subprocess.Popen( ["appium", "-p", port.__str__(), "-bp", bport.__str__()], stdout=out, stderr=subprocess.STDOUT, ) atexit.register(process.kill) - file_path = file while True: sleep(0.5) out = open(file_path) @@ -462,21 +461,20 @@ def __local_run_ios(url, desired_caps, use_port, udid, log_file): os.getenv("PYTEST_XDIST_WORKER").split("w")[1] ) logger.log(f"running: appium -p {port.__str__()}") - root_dir = os.path.join("./logs", "appium_logs") - Path(root_dir).mkdir(parents=True, exist_ok=True) + log_dir = os.path.join("./logs", "appium_logs") + Path(log_dir).mkdir(parents=True, exist_ok=True) file_path: str if log_file == "appium-stdout.log": - file = os.path.join(root_dir, f"testui-{udid}-{time.time()}-" + log_file) + file_path = os.path.join(log_dir, f"testui-{udid}-{time.time()}-" + log_file) else: - file = os.path.join(root_dir, log_file) - with open(file, "wb") as out: + file_path = os.path.join(log_dir, log_file) + with open(file_path, "wb") as out: process = subprocess.Popen( ["appium", "-p", port.__str__()], stdout=out, stderr=subprocess.STDOUT, ) atexit.register(process.kill) - file_path = file if udid is None: desired_caps = __set_ios_device(desired_caps, device) while True: diff --git a/testui/support/parallel.py b/testui/support/parallel.py index 81a44ae..db8fa78 100644 --- a/testui/support/parallel.py +++ b/testui/support/parallel.py @@ -105,6 +105,16 @@ def remove_logs(): i = 0 try: for filename in os.listdir(root_dir): + file_path = os.path.join(root_dir, filename) + os.remove(file_path) + if i == 0: + logger.log("Cleaning logs folder...") + i += 1 + except FileNotFoundError: + pass + i = 0 + try: + for filename in os.listdir(os.path.join(root_dir, "appium_logs")): file_path = os.path.join(root_dir, filename) os.remove(file_path) if i == 0: From ec7eb2bb29ef339fd313c49437d86dcd14068972 Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Mon, 24 Jul 2023 11:21:27 +0200 Subject: [PATCH 7/8] fix log_dir-root_dir folder and exception handling in remove_logs --- testui/support/logger.py | 12 ++++++------ testui/support/parallel.py | 20 ++++++++++---------- testui/support/testui_driver.py | 24 ++++++++++++------------ 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/testui/support/logger.py b/testui/support/logger.py index 7bce70d..a27f159 100644 --- a/testui/support/logger.py +++ b/testui/support/logger.py @@ -2,7 +2,7 @@ from datetime import datetime from pathlib import Path -ROOT_DIR = "./logs" +LOG_DIR = "./logs" class bcolors: """ @@ -146,12 +146,12 @@ def __file_log(log_file="stdout.log"): :param log_file: String :return: String """ - Path(ROOT_DIR).mkdir(parents=True, exist_ok=True) + Path(LOG_DIR).mkdir(parents=True, exist_ok=True) file_name: str if log_file == "stdout.log": - file_name = os.path.join(ROOT_DIR, f"TEST_UI-{log_file}") + file_name = os.path.join(LOG_DIR, f"TEST_UI-{log_file}") else: - file_name = os.path.join(ROOT_DIR, log_file) + file_name = os.path.join(LOG_DIR, log_file) return file_name @@ -161,5 +161,5 @@ def __file_tests(log_file="report_cases.txt"): :param log_file: String :return: String """ - Path(ROOT_DIR).mkdir(parents=True, exist_ok=True) - return os.path.join(ROOT_DIR, log_file) + Path(LOG_DIR).mkdir(parents=True, exist_ok=True) + return os.path.join(LOG_DIR, log_file) diff --git a/testui/support/parallel.py b/testui/support/parallel.py index db8fa78..fc207e5 100644 --- a/testui/support/parallel.py +++ b/testui/support/parallel.py @@ -89,38 +89,38 @@ def remove_logs(): """ Will remove the logs from the previous execution. """ - root_dir = "./logs" + log_dir = "./logs" i = 0 try: - for filename in os.listdir(os.path.join(root_dir, "report_screenshots")): + for filename in os.listdir(os.path.join(log_dir, "report_screenshots")): file_path = os.path.join( - os.path.join(root_dir, "report_screenshots"), filename + os.path.join(log_dir, "report_screenshots"), filename ) os.remove(file_path) if i == 0: logger.log("Cleaning report_screenshots folder...") i += 1 - except FileNotFoundError: + except (IsADirectoryError, PermissionError, FileNotFoundError): pass i = 0 try: - for filename in os.listdir(root_dir): - file_path = os.path.join(root_dir, filename) + for filename in os.listdir(log_dir): + file_path = os.path.join(log_dir, filename) os.remove(file_path) if i == 0: logger.log("Cleaning logs folder...") i += 1 - except FileNotFoundError: + except (IsADirectoryError, PermissionError, FileNotFoundError): pass i = 0 try: - for filename in os.listdir(os.path.join(root_dir, "appium_logs")): - file_path = os.path.join(root_dir, filename) + for filename in os.listdir(os.path.join(log_dir, "appium_logs")): + file_path = os.path.join(log_dir, filename) os.remove(file_path) if i == 0: logger.log("Cleaning appium_logs folder...") i += 1 - except FileNotFoundError: + except (IsADirectoryError, PermissionError, FileNotFoundError): pass diff --git a/testui/support/testui_driver.py b/testui/support/testui_driver.py index 47e95e7..a90b064 100644 --- a/testui/support/testui_driver.py +++ b/testui/support/testui_driver.py @@ -297,19 +297,19 @@ def save_screenshot(self, image_name=""): """ config = self.__configuration - root_dir = config.screenshot_path + log_dir = config.screenshot_path if not config.screenshot_path: - root_dir = "./logs" - root_dir = path.join(root_dir, "report_screenshots") + log_dir = "./logs" + log_dir = path.join(log_dir, "report_screenshots") - Path(root_dir).mkdir(parents=True, exist_ok=True) + Path(log_dir).mkdir(parents=True, exist_ok=True) current_time = datetime.now().strftime("%Y-%m-%d%H%M%S") if not image_name: image_name = f"ERROR-{self.device_name}-{current_time}.png" - final_path = path.join(root_dir, image_name) + final_path = path.join(log_dir, image_name) self.get_driver().save_screenshot(final_path) @@ -431,9 +431,9 @@ def stop_recording_screen(self, file_name="testui-video.mp4"): """ file = self.get_driver().stop_recording_screen() decoded_string = base64.b64decode(file) - root_dir = self.configuration.screenshot_path - logger.log(f"Recording stopped in {os.path.join(root_dir, file_name)}") - with open(os.path.join(root_dir, file_name), "wb") as wfile: + log_dir = self.configuration.screenshot_path + logger.log(f"Recording stopped in {os.path.join(log_dir, file_name)}") + with open(os.path.join(log_dir, file_name), "wb") as wfile: wfile.write(decoded_string) def stop_recording_and_compare( @@ -459,16 +459,16 @@ def stop_recording_and_compare( current_time = now.strftime("%Y-%m-%d%H%M%S") video_name = f"{self.device_udid}{current_time}.mp4" self.stop_recording_screen(video_name) - root_dir = "./logs" + log_dir = "./logs" if self.__configuration.screenshot_path != "": - root_dir = self.__configuration.screenshot_path + log_dir = self.__configuration.screenshot_path found = ImageRecognition( video_name, comparison, threshold, device_name=self.device_name, - path=root_dir + path=log_dir ).compare_video(keep_image_as, frame_rate_reduction=fps_reduction) - os.remove(os.path.join(root_dir, video_name)) + os.remove(os.path.join(log_dir, video_name)) if not found and not not_found: if assertion: raise Exception( From 19b5df75bc49fd1837ca5ff54a8f0b9bc4e58807 Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Mon, 24 Jul 2023 11:49:26 +0200 Subject: [PATCH 8/8] change order for remove logs --- testui/support/parallel.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/testui/support/parallel.py b/testui/support/parallel.py index fc207e5..0b0f0b7 100644 --- a/testui/support/parallel.py +++ b/testui/support/parallel.py @@ -104,21 +104,21 @@ def remove_logs(): pass i = 0 try: - for filename in os.listdir(log_dir): + for filename in os.listdir(os.path.join(log_dir, "appium_logs")): file_path = os.path.join(log_dir, filename) os.remove(file_path) if i == 0: - logger.log("Cleaning logs folder...") + logger.log("Cleaning appium_logs folder...") i += 1 except (IsADirectoryError, PermissionError, FileNotFoundError): pass i = 0 try: - for filename in os.listdir(os.path.join(log_dir, "appium_logs")): + for filename in os.listdir(log_dir): file_path = os.path.join(log_dir, filename) os.remove(file_path) if i == 0: - logger.log("Cleaning appium_logs folder...") + logger.log("Cleaning logs folder...") i += 1 except (IsADirectoryError, PermissionError, FileNotFoundError): pass