From 9b8056c59837bd1b256e4ac5a41e6756119da5bd Mon Sep 17 00:00:00 2001 From: Hani Yacoub Date: Mon, 10 Nov 2025 14:37:30 +0200 Subject: [PATCH 1/2] Stabilize csv tests --- modules/page_object_about_pages.py | 25 ++++++++++++++++--- .../test_password_csv_correctness.py | 1 - .../test_password_csv_export.py | 1 - 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/modules/page_object_about_pages.py b/modules/page_object_about_pages.py index c23761936..f4241ea4c 100644 --- a/modules/page_object_about_pages.py +++ b/modules/page_object_about_pages.py @@ -10,6 +10,7 @@ from selenium.webdriver import Firefox from selenium.webdriver.common.keys import Keys from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait from modules.page_base import BasePage from modules.page_object_generics import GenericPage @@ -194,10 +195,28 @@ def remove_password_csv(self, downloads_dir): if delete_files_regex.match(file): os.remove(passwords_csv) - def verify_csv_export(self, downloads_folder: str, filename: str): - """Wait until the exported CSV file is present in the target folder.""" + def verify_csv_export(self, downloads_folder: str, filename: str, timeout: int = 20): + """ + Wait until the exported CSV file is present, non-empty, and readable. + """ csv_file = os.path.join(downloads_folder, filename) - self.wait.until(lambda _: os.path.exists(csv_file)) + + def file_ready(_): + if not os.path.exists(csv_file): + return False + try: + # Check if file has data + if os.path.getsize(csv_file) == 0: + return False + # Try to open and read a few bytes to confirm readability + with open(csv_file, "r", encoding="utf-8") as f: + f.read(10) + return True + except (OSError, PermissionError): + # File exists but is not yet fully written or locked — retry + return False + + WebDriverWait(self.driver, timeout).until(file_ready) return csv_file def add_login(self, origin: str, username: str, password: str): diff --git a/tests/password_manager/test_password_csv_correctness.py b/tests/password_manager/test_password_csv_correctness.py index 10cf7ee5c..4a8baae5b 100644 --- a/tests/password_manager/test_password_csv_correctness.py +++ b/tests/password_manager/test_password_csv_correctness.py @@ -14,7 +14,6 @@ def test_case(): return "2241522" -@pytest.mark.unstable(reason="Bug 1996004") @pytest.mark.headed @pytest.mark.noxvfb def test_password_csv_correctness( diff --git a/tests/password_manager/test_password_csv_export.py b/tests/password_manager/test_password_csv_export.py index 576b1e9a1..00b3096ad 100644 --- a/tests/password_manager/test_password_csv_export.py +++ b/tests/password_manager/test_password_csv_export.py @@ -13,7 +13,6 @@ def test_case(): return "2241521" -@pytest.mark.unstable(reason="Bug 1996005") @pytest.mark.headed @pytest.mark.noxvfb def test_password_csv_export( From 2b677879c05c02cf59f0924a49816398da9573f8 Mon Sep 17 00:00:00 2001 From: Hani Yacoub Date: Mon, 10 Nov 2025 17:40:26 +0200 Subject: [PATCH 2/2] add log --- modules/page_object_about_pages.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/page_object_about_pages.py b/modules/page_object_about_pages.py index f4241ea4c..8a98fa5b2 100644 --- a/modules/page_object_about_pages.py +++ b/modules/page_object_about_pages.py @@ -202,18 +202,23 @@ def verify_csv_export(self, downloads_folder: str, filename: str, timeout: int = csv_file = os.path.join(downloads_folder, filename) def file_ready(_): + # Check if the file path exists. If not, continue if not os.path.exists(csv_file): return False try: - # Check if file has data + # Verify that the file isn't empty if os.path.getsize(csv_file) == 0: return False - # Try to open and read a few bytes to confirm readability + + # Attempt to read a few bytes to ensure the file is unlocked + # and readable (handles cases where the OS is still writing). with open(csv_file, "r", encoding="utf-8") as f: f.read(10) return True - except (OSError, PermissionError): - # File exists but is not yet fully written or locked — retry + + except (OSError, PermissionError) as e: + # Log and retry until timeout instead of failing immediately + logging.debug(f"[verify_csv_export] File not ready yet: {e}") return False WebDriverWait(self.driver, timeout).until(file_ready)