Skip to content

Commit 45e0eb5

Browse files
clean up on tests to have them be consistent.
1 parent 696bfb8 commit 45e0eb5

9 files changed

+61
-86
lines changed

modules/browser_object_find_toolbar.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ def previous_match(self) -> BasePage:
8484
@BasePage.context_chrome
8585
def rewind_to_first_match(self) -> BasePage:
8686
"""Go back to match 1 of n"""
87-
print(self.match_dict)
8887
while self.match_dict["current"] != 1:
89-
print(self.match_dict)
9088
self.previous_match()
9189
return self
9290

tests/pdf_viewer/test_add_image_pdf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ def test_case():
1919

2020

2121
@pytest.mark.headed
22-
def test_add_image_pdf(driver: Firefox, sys_platform, pdf_file_path: str):
22+
def test_add_image_pdf(driver: Firefox, sys_platform, pdf_viewer: GenericPdf):
2323
"""
2424
C2228202: Verify that the user is able to add an image to a PDF file.
2525
2626
Arguments:
2727
sys_platform: Current System Platform Type
28-
pdf_file_path: pdf file directory path
28+
pdf_viewer: instance of GenericPdf with correct path.
2929
"""
30-
pdf_viewer = GenericPdf(driver, pdf_url=f"file://{pdf_file_path}").open()
3130
context_menu = ContextMenu(driver)
3231
image_path = Path("data") / IMAGE_FILE_NAME
3332
pdf_viewer.add_image(str(image_path.absolute()), sys_platform)

tests/pdf_viewer/test_download_pdf_with_form_fields.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def delete_files_regex_string():
2222
@pytest.mark.headed
2323
def test_download_pdf_with_form_fields(
2424
driver: Firefox,
25-
fillable_pdf_url: str,
25+
pdf_viewer: GenericPdf,
2626
sys_platform,
2727
delete_files,
2828
downloads_folder: str,
@@ -34,23 +34,21 @@ def test_download_pdf_with_form_fields(
3434
3535
Arguments:
3636
sys_platform: Current System Platform Type
37-
fillable_pdf_url: pdf file directory path
37+
pdf_viewer: instance of GenericPdf with correct path.
3838
downloads_folder: downloads folder path
3939
delete_files: fixture to remove the files after the test finishes
4040
"""
41-
42-
pdf_page = GenericPdf(driver, pdf_url=fillable_pdf_url).open()
4341
keyboard = Controller()
4442

4543
# Fill in the name field and click on download button
46-
pdf_page.fill_element("first-name-field", "Mark")
44+
pdf_viewer.fill_element("first-name-field", "Mark")
4745
sleep(2)
4846

49-
pdf_page.click_download_button()
47+
pdf_viewer.click_download_button()
5048

5149
# Allow time for the download dialog to appear and handle the prompt
5250
sleep(2)
53-
pdf_page.handle_os_download_confirmation(keyboard, sys_platform)
51+
pdf_viewer.handle_os_download_confirmation(keyboard, sys_platform)
5452

5553
# Allow time for the download to complete
5654
sleep(3)
@@ -66,4 +64,4 @@ def test_download_pdf_with_form_fields(
6664
# Open the saved pdf and check if the edited field is displayed
6765
driver.get("file://" + os.path.realpath(saved_pdf_location))
6866

69-
pdf_page.element_visible("edited-name-field")
67+
pdf_viewer.element_visible("edited-name-field")

tests/pdf_viewer/test_download_triggered_on_content_disposition_attachment.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import pytest
44
from selenium.webdriver import Firefox
5-
from selenium.webdriver.common.by import By
6-
from selenium.webdriver.common.keys import Keys
75

86
from modules.browser_object import Navigation, TabBar
97
from modules.page_object import AboutPrefs, GenericPdf

tests/pdf_viewer/test_open_pdf_in_FF.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,13 @@ def file_name():
1616
return PDF_FILE_NAME
1717

1818

19-
def test_open_pdf_in_fx(driver: Firefox, pdf_file_path: str):
19+
def test_open_pdf_in_fx(driver: Firefox, pdf_viewer: GenericPdf):
2020
"""
2121
C936503: PDF files can be successfully opened in Firefox
2222
2323
Arguments:
24-
pdf_file_path: pdf file directory path
24+
pdf_viewer: instance of GenericPdf with correct path.
2525
"""
26-
27-
file_url = f"file://{pdf_file_path}"
28-
pdf = GenericPdf(driver, pdf_url=file_url)
29-
pdf.open()
30-
3126
# Verify that the PDF viewer is loaded
32-
pdf.url_contains("pdf")
33-
pdf.title_contains(PDF_FILE_NAME)
27+
pdf_viewer.url_contains("pdf")
28+
pdf_viewer.title_contains(PDF_FILE_NAME)

tests/pdf_viewer/test_pdf_data_can_be_cleared.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from modules.page_object import GenericPdf
66

7+
TEST_NAME = "John Doe"
8+
79

810
@pytest.fixture()
911
def test_case():
@@ -20,13 +22,15 @@ def hard_quit():
2022
return True
2123

2224

23-
TEST_NAME = "John Doe"
25+
@pytest.fixture()
26+
def file_name():
27+
return "i-9.pdf"
2428

2529

2630
@pytest.mark.ci
2731
def test_pdf_data_can_be_cleared(
2832
driver: Firefox,
29-
fillable_pdf_url: str,
33+
pdf_viewer: GenericPdf,
3034
downloads_folder: str,
3135
sys_platform,
3236
delete_files,
@@ -36,48 +40,40 @@ def test_pdf_data_can_be_cleared(
3640
3741
Arguments:
3842
sys_platform: Current System Platform Type
39-
fillable_pdf_url: pdf file directory path
43+
pdf_viewer: instance of GenericPdf with correct path.
4044
downloads_folder: downloads folder path
4145
delete_files: fixture to remove the files after the test finishes
4246
"""
43-
44-
pdf = GenericPdf(driver, pdf_url=fillable_pdf_url)
45-
pdf.open()
46-
4747
# Step 1: Click and type inside the text field for the name section
4848

49-
pdf.fill("first-name-field", TEST_NAME)
50-
pdf.element_attribute_contains("first-name-field", "value", TEST_NAME)
49+
pdf_viewer.fill("first-name-field", TEST_NAME)
50+
pdf_viewer.element_attribute_contains("first-name-field", "value", TEST_NAME)
5151

5252
# Step 2: Click over any checkbox and assert the status is updated
5353

54-
checkbox = pdf.select_and_return_checkbox("first-checkbox")
55-
pdf.element_selected("first-checkbox")
54+
checkbox = pdf_viewer.select_and_return_checkbox("first-checkbox")
55+
pdf_viewer.element_selected("first-checkbox")
5656

5757
# Step 3: Select an option from a dropdown and verify the selection
5858

59-
dropdown_option = pdf.select_and_return_dropdown_option(
59+
dropdown_option = pdf_viewer.select_and_return_dropdown_option(
6060
"state-dropdown-field", By.XPATH, "//option[@value='CA']"
6161
)
62-
pdf.expect(lambda _: dropdown_option.is_displayed())
62+
pdf_viewer.expect(lambda _: dropdown_option.is_displayed())
6363

6464
# Step 4: Delete the text added in step 1 and ensure the input field is empty
65-
pdf.get_element("first-name-field").clear()
66-
pdf.expect(lambda _: not pdf.get_element("first-name-field").get_attribute("value"))
65+
pdf_viewer.get_element("first-name-field").clear()
66+
pdf_viewer.expect(
67+
lambda _: not pdf_viewer.get_element("first-name-field").get_attribute("value")
68+
)
6769

6870
# Step 5: Click the checkbox from step 2 again and ensure it returns to its previous state
6971
checkbox.click()
70-
pdf.expect(lambda _: not checkbox.is_selected())
72+
pdf_viewer.expect(lambda _: not checkbox.is_selected())
7173

7274
# Step 6: Clear the state selection and ensure the field is empty
73-
default_option = pdf.select_and_return_dropdown_option(
75+
default_option = pdf_viewer.select_and_return_dropdown_option(
7476
"state-dropdown-field", By.XPATH, "//option[@value=' ']"
7577
)
7678
default_option.click()
77-
pdf.expect(lambda _: default_option.is_selected())
78-
79-
# Assert that all fields are reset to their default state
80-
assert (
81-
pdf.get_element("first-name-field").get_attribute("value") == ""
82-
), "Text field did not reset."
83-
assert not checkbox.is_selected(), "Checkbox did not reset."
79+
pdf_viewer.expect(lambda _: default_option.is_selected())

tests/pdf_viewer/test_pdf_download.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ def test_case():
1313
return "3932"
1414

1515

16-
@pytest.fixture()
17-
def add_prefs():
18-
return []
19-
20-
2116
@pytest.fixture()
2217
def delete_files_regex_string():
2318
return r"i-9.*\.pdf"
@@ -31,7 +26,7 @@ def file_name():
3126
@pytest.mark.headed
3227
def test_pdf_download(
3328
driver: Firefox,
34-
fillable_pdf_url: str,
29+
pdf_viewer: GenericPdf,
3530
downloads_folder: str,
3631
sys_platform,
3732
delete_files,
@@ -43,28 +38,25 @@ def test_pdf_download(
4338
4439
Arguments:
4540
sys_platform: Current System Platform Type
46-
fillable_pdf_url: pdf file directory path
41+
pdf_viewer: instance of GenericPdf with correct path.
4742
downloads_folder: downloads folder path
4843
delete_files: fixture to remove the files after the test finishes
4944
file_name: pdf file name
5045
"""
5146
from pynput.keyboard import Controller
5247

53-
pdf = GenericPdf(driver, pdf_url=fillable_pdf_url)
54-
pdf.open()
55-
5648
keyboard = Controller()
5749

5850
# Click the download button
59-
pdf.click_download_button()
51+
pdf_viewer.click_download_button()
6052

6153
# Allow time for the download dialog m to appear and pressing enter to download
6254
sleep(2)
63-
pdf.handle_os_download_confirmation(keyboard, sys_platform)
55+
pdf_viewer.handle_os_download_confirmation(keyboard, sys_platform)
6456

6557
# Set the expected download path and the expected PDF name
6658
saved_pdf_location = os.path.join(downloads_folder, file_name)
67-
pdf.expect(lambda _: os.path.exists(saved_pdf_location))
59+
pdf_viewer.expect(lambda _: os.path.exists(saved_pdf_location))
6860

6961
# Verify if the file exists
7062
assert os.path.exists(

tests/pdf_viewer/test_pdf_input_numbers.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ def hard_quit():
2222
return True
2323

2424

25+
@pytest.fixture()
26+
def file_name():
27+
return "i-9.pdf"
28+
29+
2530
def test_pdf_input_numbers(
2631
driver: Firefox,
27-
fillable_pdf_url: str,
32+
pdf_viewer: GenericPdf,
2833
downloads_folder: str,
2934
sys_platform,
3035
delete_files,
@@ -34,15 +39,13 @@ def test_pdf_input_numbers(
3439
3540
Arguments:
3641
sys_platform: Current System Platform Type
37-
fillable_pdf_url: pdf file directory path
42+
pdf_viewer: instance of GenericPdf with correct path.
3843
downloads_folder: downloads folder path
3944
delete_files: fixture to remove the files after the test finishes
4045
"""
4146

42-
pdf = GenericPdf(driver, pdf_url=fillable_pdf_url)
43-
4447
# Clear the field and enter the test value
45-
pdf.fill_element("zipcode-field", TEST_VALUE + Keys.TAB)
48+
pdf_viewer.fill_element("zipcode-field", TEST_VALUE + Keys.TAB)
4649

4750
# Verify the value is still present
48-
pdf.element_attribute_contains("zipcode-field", "value", TEST_VALUE)
51+
pdf_viewer.element_attribute_contains("zipcode-field", "value", TEST_VALUE)

tests/pdf_viewer/test_zoom_pdf_viewer.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,63 +13,59 @@ def test_case():
1313

1414

1515
@pytest.mark.parametrize("control", controls)
16-
def test_zoom_pdf_viewer_toolbar(driver: Firefox, fillable_pdf_url: str, control: str):
16+
def test_zoom_pdf_viewer_toolbar(driver: Firefox, pdf_viewer: GenericPdf, control: str):
1717
"""
1818
C3928: ensure that in the pdf viewer you can zoom in and out
1919
2020
Arguments:
2121
control: zoom controls
22-
fillable_pdf_url: pdf file directory path
22+
pdf_viewer: instance of GenericPdf with correct path.
2323
"""
24-
zoom_pdf_viewer(driver, fillable_pdf_url, control, "Tools")
24+
zoom_pdf_viewer(pdf_viewer, control, "Tools")
2525

2626

2727
@pytest.mark.parametrize("control", controls)
28-
def test_zoom_pdf_viewer_keys(driver: Firefox, fillable_pdf_url: str, control: str):
28+
def test_zoom_pdf_viewer_keys(driver: Firefox, pdf_viewer: GenericPdf, control: str):
2929
"""
3030
C3928: ensure that in the pdf viewer you can zoom in and out
3131
3232
Arguments:
3333
control: zoom controls
34-
fillable_pdf_url: pdf file directory path
34+
pdf_viewer: instance of GenericPdf with correct path.
3535
"""
36-
zoom_pdf_viewer(driver, fillable_pdf_url, control, "Keys")
36+
zoom_pdf_viewer(pdf_viewer, control, "Keys")
3737

3838

39-
def zoom_pdf_viewer(
40-
driver: Firefox, fillable_pdf_url: str, control: str, input_type: str
41-
):
39+
def zoom_pdf_viewer(pdf_viewer: GenericPdf, control: str, input_type: str):
4240
"""
4341
zoom base function to change based on input_type
4442
4543
Arguments:
46-
driver: Firefox webdriver
4744
control: zoom controls
48-
fillable_pdf_url: pdf file directory path
45+
pdf_viewer: instance of GenericPdf with correct path.
4946
input_type: Keys or Tool
5047
"""
51-
pdf_page = GenericPdf(driver, pdf_url=fillable_pdf_url).open()
5248
pdf_zoom = {
53-
"zoom_out": pdf_page.zoom_out_keys
49+
"zoom_out": pdf_viewer.zoom_out_keys
5450
if input_type == "Keys"
55-
else pdf_page.zoom_out_toolbar,
56-
"zoom_in": pdf_page.zoom_in_keys
51+
else pdf_viewer.zoom_out_toolbar,
52+
"zoom_in": pdf_viewer.zoom_in_keys
5753
if input_type == "Keys"
58-
else pdf_page.zoom_in_toolbar,
54+
else pdf_viewer.zoom_in_toolbar,
5955
}
60-
body = pdf_page.get_element("pdf-body")
56+
body = pdf_viewer.get_element("pdf-body")
6157
before_scale_factor = float(body.value_of_css_property("--scale-factor"))
6258

6359
if control == "out":
6460
pdf_zoom["zoom_out"]()
65-
pdf_page.wait.until(
61+
pdf_viewer.wait.until(
6662
lambda _: float(body.value_of_css_property("--scale-factor"))
6763
< before_scale_factor
6864
)
6965
assert float(body.value_of_css_property("--scale-factor")) < before_scale_factor
7066
else:
7167
pdf_zoom["zoom_in"]()
72-
pdf_page.wait.until(
68+
pdf_viewer.wait.until(
7369
lambda _: float(body.value_of_css_property("--scale-factor"))
7470
> before_scale_factor
7571
)

0 commit comments

Comments
 (0)