Skip to content

Commit c3ae19f

Browse files
committed
Update tests and methods to target Documents folder
1 parent 173d054 commit c3ae19f

File tree

3 files changed

+28
-31
lines changed

3 files changed

+28
-31
lines changed

modules/page_object_about_pages.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,17 @@ def check_logins_present(
179179
else:
180180
assert expected_logins == actual_logins
181181

182-
def remove_password_csv(self, home_folder):
183-
# Delete password.csv, if there is one in test location
184-
if self.sys_platform == "Linux":
185-
downloads_folder = os.getcwd()
186-
else:
187-
downloads_folder = os.path.join(home_folder, "Downloads")
188-
passwords_csv = os.path.join(downloads_folder, "passwords.csv")
189-
for file in os.listdir(downloads_folder):
182+
def get_documents_dir(self) -> str:
183+
# Return full path to Documents directory
184+
home = os.path.expanduser("~")
185+
export_dir = os.path.join(home, "Documents")
186+
return export_dir
187+
188+
def remove_password_csv(self):
189+
# Delete password.csv, if there is one in the export location
190+
documents_dir = self.get_documents_dir()
191+
passwords_csv = os.path.join(documents_dir, "passwords.csv")
192+
for file in os.listdir(documents_dir):
190193
delete_files_regex = re.compile(r"\bpasswords.csv\b")
191194
if delete_files_regex.match(file):
192195
os.remove(passwords_csv)

tests/password_manager/test_password_csv_correctness.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ def test_case():
2222
@pytest.mark.headed
2323
def test_password_csv_correctness(driver_and_saved_logins, home_folder, sys_platform):
2424
"""
25-
C2241522: Check that password.csv displays the correct information
25+
C2241522: Verify than an exported password.csv file displays the correct information
2626
"""
2727
# Initializing objects
2828
(driver, usernames, logins) = driver_and_saved_logins
2929
about_logins = AboutLogins(driver)
3030
keyboard = Controller()
3131

32-
# Ensure the Downloads folder doesn't contain a passwords.csv file
33-
about_logins.remove_password_csv(home_folder)
32+
# Ensure the export target folder doesn't contain a passwords.csv file
33+
about_logins.remove_password_csv()
3434

3535
# Click on buttons to export passwords
3636
about_logins.open()
@@ -42,20 +42,17 @@ def test_password_csv_correctness(driver_and_saved_logins, home_folder, sys_plat
4242
time.sleep(5)
4343
keyboard.tap(Key.enter)
4444

45-
# Verify that the file exists
46-
if sys_platform == "Linux":
47-
downloads_folder = os.getcwd()
48-
else:
49-
downloads_folder = os.path.join(home_folder, "Downloads")
50-
passwords_csv = os.path.join(downloads_folder, "passwords.csv")
51-
about_logins.wait.until(lambda _: os.path.exists(passwords_csv))
45+
# Verify the exported csv file is present in the target folder
46+
documents_directory = about_logins.get_documents_dir()
47+
csv_file = os.path.join(documents_directory, "passwords.csv")
48+
about_logins.wait.until(lambda _: os.path.exists(csv_file))
5249

5350
# Verify the results
5451
guid_pattern = re.compile(
5552
r"{[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}}"
5653
)
5754
time_pattern = re.compile(r"[0-9]{10}")
58-
with open(passwords_csv) as pw:
55+
with open(csv_file) as pw:
5956
reader = csv.DictReader(pw)
6057
actual_logins = {}
6158
for row in reader:
@@ -69,4 +66,4 @@ def test_password_csv_correctness(driver_and_saved_logins, home_folder, sys_plat
6966
about_logins.check_logins_present(actual_logins, logins)
7067

7168
# Delete the password.csv created
72-
about_logins.remove_password_csv(home_folder)
69+
about_logins.remove_password_csv()

tests/password_manager/test_password_csv_export.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ def test_password_csv_export(
2222
driver_and_saved_logins, home_folder, sys_platform, opt_ci
2323
):
2424
"""
25-
C2241521: Check that password.csv can be downloaded from about:logins
25+
C2241521: Verify that a password.csv file can be exported from about:logins
2626
"""
2727
# Initializing objects
2828
(driver, usernames, logins) = driver_and_saved_logins
2929
about_logins = AboutLogins(driver)
3030
keyboard = Controller()
3131

32-
# Ensure the Downloads folder doesn't contain a passwords.csv file
33-
about_logins.remove_password_csv(home_folder)
32+
# Ensure the export target folder doesn't contain a passwords.csv file
33+
about_logins.remove_password_csv()
3434

3535
# Click on buttons to export passwords
3636
about_logins.open()
@@ -42,13 +42,10 @@ def test_password_csv_export(
4242
time.sleep(5)
4343
keyboard.tap(Key.enter)
4444

45-
# Verify that the file exists
46-
if sys_platform == "Linux":
47-
downloads_folder = os.getcwd()
48-
else:
49-
downloads_folder = os.path.join(home_folder, "Downloads")
50-
passwords_csv = os.path.join(downloads_folder, "passwords.csv")
51-
about_logins.wait.until(lambda _: os.path.exists(passwords_csv))
45+
# Verify the exported csv file is present in the target folder
46+
documents_directory = about_logins.get_documents_dir()
47+
csv_file = os.path.join(documents_directory, "passwords.csv")
48+
about_logins.wait.until(lambda _: os.path.exists(csv_file))
5249

5350
# Delete the password.csv created
54-
about_logins.remove_password_csv(home_folder)
51+
about_logins.remove_password_csv()

0 commit comments

Comments
 (0)