Skip to content

Commit 90b9936

Browse files
Refactor finished.
1 parent c2c5e99 commit 90b9936

File tree

6 files changed

+130
-118
lines changed

6 files changed

+130
-118
lines changed

modules/browser_object_navigation.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ def set_search_mode(self, search_mode: str) -> BasePage:
213213
raise ValueError("search location is not valid.")
214214
# switch to chrome context
215215
# get list of all valid search modes and filter by label
216-
self.get_element(
217-
"search-mode-switcher-option", labels=[search_mode]
218-
).click()
216+
self.get_element("search-mode-switcher-option", labels=[search_mode]).click()
219217
return self
220218

221219
def context_click_in_awesome_bar(self) -> BasePage:
@@ -224,6 +222,7 @@ def context_click_in_awesome_bar(self) -> BasePage:
224222
actions.context_click(self.awesome_bar).perform()
225223
return self
226224

225+
@BasePage.context_chrome
227226
def get_download_button(self) -> WebElement:
228227
"""
229228
Gets the download button WebElement

modules/data/generic_pdf.components.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
]
88
},
99

10+
"pdf-text-layer": {
11+
"selectorData": "textLayer",
12+
"strategy": "class",
13+
"groups": []
14+
},
15+
1016
"html-body": {
1117
"selectorData": "html",
1218
"strategy": "tag",

modules/page_object_generics.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
from termios import VLNEXT
12
from time import sleep
3+
from typing import Literal
24

5+
from selenium.webdriver import Firefox
36
from selenium.webdriver.common.by import By
47
from selenium.webdriver.common.keys import Keys
58
from selenium.webdriver.remote.webelement import WebElement
@@ -22,6 +25,13 @@ class GenericPdf(BasePage):
2225

2326
URL_TEMPLATE = "{pdf_url}"
2427

28+
def __init__(self, driver: Firefox, **kwargs):
29+
super().__init__(driver, **kwargs)
30+
self.open()
31+
self.html_body = self.get_element("html-body")
32+
self.pdf_body = self.get_element("pdf-body")
33+
self.max_page = int(self.get_element("page-input").get_attribute("max"))
34+
2535
def get_green_highlighted_text(self) -> str:
2636
return self.get_element("highlighted-text").get_attribute("innerText")
2737

@@ -48,6 +58,8 @@ def zoom_out_keys(self) -> BasePage:
4858
return self
4959

5060
def jump_to_page(self, page_number: int) -> BasePage:
61+
if page_number > self.max_page or not isinstance(page_number, int):
62+
raise ValueError("Page Number is not valid.")
5163
page_input = self.get_element("page-input")
5264
self.double_click(page_input)
5365
page_input.send_keys(Keys.BACK_SPACE + str(page_number) + Keys.ENTER)
@@ -58,6 +70,11 @@ def open_toolbar_menu(self) -> BasePage:
5870
self.element_visible("toolbar-container")
5971
return self
6072

73+
def select_toolbar_option(self, option: str) -> BasePage:
74+
self.open_toolbar_menu()
75+
self.get_element(option).click()
76+
return self
77+
6178
def add_image(self, image_path: str, sys_platform: str) -> BasePage:
6279
self.get_element("toolbar-add-image").click()
6380
self.get_element("toolbar-add-image-confirm").click()
@@ -105,3 +122,17 @@ def select_and_return_dropdown_option(
105122
dropdown_option = self.find_element(selector, value)
106123
dropdown_option.click()
107124
return dropdown_option
125+
126+
def get_first_text_element(self) -> WebElement:
127+
"""get first text element in pdf"""
128+
return self.pdf_body.find_element(By.TAG_NAME, "span")
129+
130+
def navigate_page_by_keys(self, key: str):
131+
self.html_body.send_keys(key)
132+
return self
133+
134+
def navigate_page_by_scroll_key(self, direction: str) -> BasePage:
135+
if direction not in {"next", "prev"}:
136+
raise ValueError("incorrect scroll value.")
137+
self.get_element(f"scroll-{direction}").click()
138+
return self

tests/pdf_viewer/conftest.py

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

33
import pytest
44

5+
from modules.page_object import GenericPdf
6+
57

68
@pytest.fixture()
79
def suite_id():
@@ -24,3 +26,8 @@ def pdf_file_path(tmp_path, file_name: str):
2426
loc = tmp_path / file_name
2527
copyfile(f"data/{file_name}", loc)
2628
return loc
29+
30+
31+
@pytest.fixture()
32+
def pdf_viewer(driver, pdf_file_path):
33+
return GenericPdf(driver, pdf_url=f"file://{pdf_file_path}")

tests/pdf_viewer/test_download_triggered_on_content_disposition_attachment.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ def test_download_panel_triggered_on_content_disposition_attachment(
5353
browser_actions.select_file_opening_option()
5454

5555
tabs.wait_for_num_tabs(2)
56-
assert (
57-
len(driver.window_handles) == 2
58-
), f"Expected 2 tabs, but found {len(driver.window_handles)}"
59-
6056
tabs.switch_to_new_tab()
61-
GenericPdf(driver, pdf_url="").url_contains("file:")
57+
## url_contains isn't working for some reason.
58+
assert (driver.current_url.endswith(".pdf"), f"New tab should be a pdf file.")

0 commit comments

Comments
 (0)