diff --git a/modules/page_object_about_pages.py b/modules/page_object_about_pages.py index c23761936..8a98fa5b2 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,33 @@ 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(_): + # Check if the file path exists. If not, continue + if not os.path.exists(csv_file): + return False + try: + # Verify that the file isn't empty + if os.path.getsize(csv_file) == 0: + return False + + # 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) 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) 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(