Skip to content

Commit 2c915f6

Browse files
working on comments on suite refactor
1 parent 0441354 commit 2c915f6

13 files changed

+148
-108
lines changed

modules/browser_object_navigation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Navigation(BasePage):
2727
def __init__(self, driver: Firefox, **kwargs):
2828
super().__init__(driver, **kwargs)
2929
self.search_bar = None
30+
self.awesome_bar = None
3031
self.change_search_settings_button = None
3132

3233
@BasePage.context_content
@@ -185,7 +186,7 @@ def context_click_in_awesome_bar(self) -> BasePage:
185186
actions = ActionChains(self.driver)
186187
actions.context_click(self.awesome_bar).perform()
187188
return self
188-
189+
189190
def get_download_button(self) -> WebElement:
190191
"""
191192
Gets the download button WebElement

modules/browser_object_tabbar.py

Lines changed: 67 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ def __init__(self):
3535

3636
SCROLL_DIRECTION = ScrollDirection()
3737

38+
@BasePage.context_chrome
3839
def new_tab_by_button(self) -> BasePage:
3940
"""Use the New Tab button (+) to open a new tab"""
40-
with self.driver.context(self.driver.CONTEXT_CHROME):
41-
self.get_element("newtab-button").click()
41+
self.get_element("newtab-button").click()
4242
return self
4343

4444
def new_tab_by_keys(self, sys_platform: str) -> BasePage:
@@ -77,60 +77,59 @@ def reopen_closed_tab_by_keys(self, sys_platform: str) -> BasePage:
7777
).key_up(Keys.SHIFT).key_up(Keys.CONTROL).perform()
7878
return self
7979

80+
@BasePage.context_chrome
8081
def click_tab_by_title(self, title: str) -> BasePage:
8182
"""Given a full page title, click the corresponding tab"""
82-
with self.driver.context(self.driver.CONTEXT_CHROME):
83-
self.get_element("tab-by-title", labels=[title]).click()
83+
self.get_element("tab-by-title", labels=[title]).click()
8484
return self
8585

86-
def get_tab_by_title(self, title: str) -> BasePage:
86+
@BasePage.context_chrome
87+
def get_tab_by_title(self, title: str) -> WebElement:
8788
"""Given a full page title, return the corresponding tab"""
88-
with self.driver.context(self.driver.CONTEXT_CHROME):
89-
return self.get_element("tab-by-title", labels=[title])
89+
return self.get_element("tab-by-title", labels=[title])
9090

91+
@BasePage.context_chrome
9192
def click_tab_by_index(self, index: int) -> BasePage:
9293
"""Given a tab index (int), click the corresponding tab"""
93-
with self.driver.context(self.driver.CONTEXT_CHROME):
94-
self.get_element("tab-by-index", labels=[str(index)]).click()
94+
self.get_element("tab-by-index", labels=[str(index)]).click()
9595
return self
9696

97+
@BasePage.context_chrome
9798
def get_tab(self, identifier: Union[str, int]) -> Union[WebElement, None]:
9899
"""Return a tab root based on either a title or an index"""
99-
with self.driver.context(self.driver.CONTEXT_CHROME):
100-
if isinstance(identifier, int):
101-
tab = self.get_element("tab-by-index", labels=[str(identifier)])
102-
elif isinstance(identifier, str):
103-
tab = self.get_element("tab-by-title", labels=[identifier])
104-
else:
105-
# if we get an unexpected type, we shouldn't assume that the user wants sys exit
106-
# but we have to cause problems for them nonetheless
107-
assert False, "Error getting tab root"
108-
tab = None
109-
return tab
100+
if isinstance(identifier, int):
101+
tab = self.get_element("tab-by-index", labels=[str(identifier)])
102+
elif isinstance(identifier, str):
103+
tab = self.get_element("tab-by-title", labels=[identifier])
104+
else:
105+
# if we get an unexpected type, we shouldn't assume that the user wants sys exit,
106+
# but we have to cause problems for them nonetheless
107+
assert False, "Error getting tab root"
108+
return tab
110109

110+
@BasePage.context_chrome
111111
def is_pinned(self, tab_root: WebElement) -> bool:
112112
"""Is this tab pinned?"""
113-
with self.driver.context(self.driver.CONTEXT_CHROME):
114-
pinned = tab_root.get_attribute("pinned")
115-
if pinned in ["true", "false"]:
116-
return pinned == "true"
117-
else:
118-
assert False, "Error checking tab pinned status"
113+
pinned = tab_root.get_attribute("pinned")
114+
if pinned in ["true", "false"]:
115+
return pinned == "true"
116+
else:
117+
assert False, "Error checking tab pinned status"
119118

119+
@BasePage.context_chrome
120120
def click_tab_mute_button(self, identifier: Union[str, int]) -> BasePage:
121121
"""Click the tab icon overlay, no matter what's happening with media"""
122122
logging.info(f"toggling tab mute for {identifier}")
123123
tab = self.get_tab(identifier)
124-
with self.driver.context(self.driver.CONTEXT_CHROME):
125-
self.actions.move_to_element(tab).perform()
126-
self.get_element("tab-icon-overlay").click()
124+
self.actions.move_to_element(tab).perform()
125+
self.get_element("tab-icon-overlay").click()
127126
return self
128127

128+
@BasePage.context_chrome
129129
def get_tab_title(self, tab_element: WebElement) -> str:
130130
"""Given a tab root element, get the title text of the tab"""
131-
with self.driver.context(self.driver.CONTEXT_CHROME):
132-
tab_label = tab_element.find_element(*self.get_selector("tab-title"))
133-
return tab_label.text
131+
tab_label = tab_element.find_element(*self.get_selector("tab-title"))
132+
return tab_label.text
134133

135134
def expect_tab_sound_status(
136135
self, identifier: Union[str, int], status: MediaStatus
@@ -147,35 +146,35 @@ def expect_title_contains(self, text: str) -> BasePage:
147146
self.expect(EC.title_contains(text))
148147
return self
149148

149+
@BasePage.context_chrome
150150
def open_all_tabs_list(self) -> BasePage:
151151
"""Click the Tab Visibility / List All Tabs button"""
152-
with self.driver.context(self.driver.CONTEXT_CHROME):
153-
self.get_element("list-all-tabs-button").click()
154-
self.expect(
155-
EC.text_to_be_present_in_element_attribute(
156-
self.get_selector("list-all-tabs-button"), "open", "true"
157-
)
152+
self.get_element("list-all-tabs-button").click()
153+
self.expect(
154+
EC.text_to_be_present_in_element_attribute(
155+
self.get_selector("list-all-tabs-button"), "open", "true"
158156
)
157+
)
159158
return self
160159

160+
@BasePage.context_chrome
161161
def count_tabs_in_all_tabs_menu(self) -> int:
162162
"""Return the number of entries in the all tabs menu"""
163-
with self.driver.context(self.driver.CONTEXT_CHROME):
164-
all_tabs_menu = self.get_element("all-tabs-menu")
165-
all_tabs_entries = all_tabs_menu.find_elements(
166-
self.get_selector("all-tabs-entry")
167-
)
163+
all_tabs_menu = self.get_element("all-tabs-menu")
164+
all_tabs_entries = all_tabs_menu.find_elements(
165+
self.get_selector("all-tabs-entry")
166+
)
168167
return len(all_tabs_entries)
169168

169+
@BasePage.context_chrome
170170
def scroll_tabs(self, direction: ScrollDirection) -> BasePage:
171171
"""Scroll tabs in tab bar using the < and > scroll buttons"""
172172
logging.info(f"Scrolling tabs {direction}")
173-
with self.driver.context(self.driver.CONTEXT_CHROME):
174-
try:
175-
scroll_button = self.get_element(f"tab-scrollbox-{direction}-button")
176-
scroll_button.click()
177-
except NoSuchElementException:
178-
logging.info("Could not scroll any further!")
173+
try:
174+
scroll_button = self.get_element(f"tab-scrollbox-{direction}-button")
175+
scroll_button.click()
176+
except NoSuchElementException:
177+
logging.info("Could not scroll any further!")
179178
return self
180179

181180
def get_text_of_all_tabs_entry(self, selected=False, index=0) -> str:
@@ -238,6 +237,7 @@ def get_location_of_all_tabs_entry(self, selected=False, index=0) -> dict:
238237
entry = entries[index]
239238
return entry.find_element(By.CLASS_NAME, "all-tabs-button").location
240239

240+
@BasePage.context_chrome
241241
def scroll_on_all_tabs_menu(self, down=True, pixels=200) -> BasePage:
242242
"""
243243
Scroll the List All Tabs menu down or up.
@@ -253,30 +253,29 @@ def scroll_on_all_tabs_menu(self, down=True, pixels=200) -> BasePage:
253253
pixels: int
254254
The number of pixels to scroll the bar
255255
"""
256-
with self.driver.context(self.driver.CONTEXT_CHROME):
257-
menu = self.get_element("all-tabs-menu")
258-
logging.info(f"menu location: {menu.location}")
259-
logging.info(f"menu size: {menu.size}")
260-
261-
# HACK: Can't figure out what the scrollbox selector is, but it's ~4 pixels
262-
# off the edge of the menu.
263-
x_start = (menu.size["width"] / 2.0) - 4.0
264-
# +Y is down, -Y is up
265-
sign = 1 if down else -1
266-
267-
self.actions.move_to_element_with_offset(menu, x_start, 0)
268-
self.actions.click_and_hold()
269-
self.actions.move_by_offset(0, (sign * pixels))
270-
self.actions.release()
271-
self.actions.perform()
272-
256+
menu = self.get_element("all-tabs-menu")
257+
logging.info(f"menu location: {menu.location}")
258+
logging.info(f"menu size: {menu.size}")
259+
260+
# HACK: Can't figure out what the scrollbox selector is, but it's ~4 pixels
261+
# off the edge of the menu.
262+
x_start = (menu.size["width"] / 2.0) - 4.0
263+
# +Y is down, -Y is up
264+
sign = 1 if down else -1
265+
266+
self.actions.move_to_element_with_offset(menu, x_start, 0)
267+
self.actions.click_and_hold()
268+
self.actions.move_by_offset(0, (sign * pixels))
269+
self.actions.release()
270+
self.actions.perform()
271+
272+
@BasePage.context_chrome
273273
def close_tab(self, tab: WebElement) -> BasePage:
274274
"""
275275
Given the index of the tab, it closes that tab.
276276
"""
277277
# cur_tab = self.click_tab_by_index(index)
278-
with self.driver.context(self.driver.CONTEXT_CHROME):
279-
self.get_element("tab-x-icon", parent_element=tab).click()
278+
self.get_element("tab-x-icon", parent_element=tab).click()
280279
return self
281280

282281
def open_web_page_in_new_tab(self, web_page: BasePage, num_tabs: int) -> BasePage:

modules/data/about_prefs.components.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,18 @@
451451
"groups": []
452452
},
453453

454+
"actions-menu": {
455+
"selectorData": "richlistitem[type='{.*}'] menulist.actionsMenu",
456+
"strategy": "css",
457+
"groups": []
458+
},
459+
460+
"actions-menu-option": {
461+
"selectorData": "richlistitem[type='{.*}'] menuitem[label='{.*}']",
462+
"strategy": "css",
463+
"groups": []
464+
},
465+
454466
"exceptions-item": {
455467
"selectorData": "//*[@id='permissionsBox']//*[@origin]",
456468
"strategy": "xpath",

modules/page_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def get_selector(self, name: str, labels=[]) -> list:
249249
match = braces.findall(selector[1])
250250
for i in range(len(labels)):
251251
logging.info(f"Replace {match[i]} with {labels[i]}")
252-
selector[1] = selector[1].replace(match[i], labels[i])
252+
selector[1] = selector[1].replace(match[i], labels[i], 1)
253253
logging.info("Returned selector.")
254254
return selector
255255

modules/page_object_prefs.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,7 @@ def fill_autofill_panel_information(
200200
self.actions.send_keys(Keys.ENTER).perform()
201201
return self
202202

203-
def fill_cc_panel_information(
204-
self, credit_card_fill_information: CreditCardBase
205-
) -> BasePage:
203+
def fill_cc_panel_information(self, credit_card_fill_information: CreditCardBase):
206204
"""
207205
Takes the sample cc object and fills it into the popup panel in the about:prefs section
208206
under saved payment methods.
@@ -237,7 +235,7 @@ def get_saved_payments_popup_iframe(self) -> WebElement:
237235
iframe = self.get_element("browser-popup")
238236
return iframe
239237

240-
def update_cc_field_panel(self, num_tabs: int, new_info: str) -> BasePage:
238+
def update_cc_field_panel(self, num_tabs: int, new_info: str):
241239
"""
242240
Updates a field in the credit card popup panel in about:prefs by pressing the number of tabs and sending the new information
243241
...
@@ -413,6 +411,17 @@ def set_default_zoom_level(self, zoom_percentage: int) -> BasePage:
413411
self.click_on("default-zoom-dropdown")
414412
return self
415413

414+
def select_content_and_action(self, content_type: str, action: str) -> BasePage:
415+
"""
416+
From the applications list that handles how downloaded media is used,
417+
select a content type and action
418+
"""
419+
el = self.get_element("actions-menu", labels=[content_type])
420+
el.click()
421+
self.click_on("actions-menu-option", labels=[content_type, action])
422+
self.wait.until(lambda _: el.get_attribute("label") == action)
423+
return self
424+
416425

417426
class AboutAddons(BasePage):
418427
"""

modules/util.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from selenium.webdriver.common.keys import Keys
2323
from selenium.webdriver.remote.shadowroot import ShadowRoot
2424
from selenium.webdriver.remote.webelement import WebElement
25+
from selenium.webdriver.support import expected_conditions as EC
26+
from selenium.webdriver.support.wait import WebDriverWait
2527

2628
from modules.classes.autofill_base import AutofillAddressBase
2729
from modules.classes.credit_card import CreditCardBase
@@ -409,6 +411,7 @@ class BrowserActions:
409411

410412
def __init__(self, driver: Firefox):
411413
self.driver = driver
414+
self.wait = WebDriverWait(driver, timeout=2)
412415

413416
def clear_and_fill(self, webelement: WebElement, term: str, press_enter=True):
414417
"""
@@ -476,6 +479,22 @@ def switch_to_content_context(self):
476479
"""
477480
self.driver.switch_to.default_content()
478481

482+
def select_file_opening_option(self, option: str = "handleInternally"):
483+
"""
484+
select an option when file opening window prompt is shown
485+
"""
486+
with self.driver.context(self.driver.CONTEXT_CHROME):
487+
self.driver.switch_to.window(self.driver.window_handles[-1])
488+
self.driver.find_element(By.ID, option).click()
489+
confirm_button = self.driver.find_element(By.ID, "unknownContentTypeWindow")
490+
self.wait.until_not(
491+
EC.element_attribute_to_include(
492+
(By.CSS_SELECTOR, ".dialog-button-box > button:nth-child(6)"),
493+
"disabled",
494+
)
495+
)
496+
confirm_button.send_keys(Keys.ENTER)
497+
479498
def get_all_colors_in_element(self, selector: tuple) -> set:
480499
"""
481500
Given an element selector, return all the unique colors in that element.

tests/find_toolbar/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ def find_toolbar(driver: Firefox):
2323

2424

2525
@pytest.fixture()
26-
def ba(driver: Firefox):
27-
browser_actions = BrowserActions(driver)
28-
yield browser_actions
26+
def browser_actions(driver: Firefox):
27+
ba = BrowserActions(driver)
28+
yield ba

tests/find_toolbar/test_find_in_pdf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_case():
1212

1313

1414
WORD_SEGMENT = "authori"
15-
MATCH_TWO_CONTEXT = "representative must complete"
15+
MATCH_TWO_COMPLETION = "representative must complete"
1616

1717

1818
class element_parent_has_text:
@@ -51,4 +51,4 @@ def test_find_in_pdf_using_key_combos(
5151

5252
find_toolbar.rewind_to_first_match()
5353
find_toolbar.navigate_matches_by_keys()
54-
pdf.expect(element_parent_has_text(pdf, "highlighted-text", MATCH_TWO_CONTEXT))
54+
pdf.expect(element_parent_has_text(pdf, "highlighted-text", MATCH_TWO_COMPLETION))

tests/find_toolbar/test_find_toolbar_nav.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ def are_lists_different(a: int, b: int) -> bool:
2828

2929

3030
def test_find_toolbar_navigation(
31-
driver: Firefox, find_toolbar: FindToolbar, ba: BrowserActions
31+
driver: Firefox, find_toolbar: FindToolbar, browser_actions: BrowserActions
3232
):
3333
"""
3434
C127249: Navigate through found items
3535
3636
Arguments:
37-
ba: instantiation of BrowserActions BOM.
37+
browser_actions: instantiation of BrowserActions BOM.
3838
find_toolbar: instantiation of FindToolbar BOM.
3939
"""
4040
driver.get(TARGET_PAGE)
@@ -49,16 +49,16 @@ def test_find_toolbar_navigation(
4949
find_toolbar.rewind_to_first_match()
5050

5151
# Ensure that first match is highlighted, others are not
52-
first_match_colors = ba.get_all_colors_in_element(first_match)
53-
fourth_match_colors = ba.get_all_colors_in_element(fourth_match)
52+
first_match_colors = browser_actions.get_all_colors_in_element(first_match)
53+
fourth_match_colors = browser_actions.get_all_colors_in_element(fourth_match)
5454

5555
assert len(first_match_colors) > len(fourth_match_colors)
5656
assert are_lists_different(len(first_match_colors), len(fourth_match_colors))
5757

5858
# Navigate with keyboard and button
5959
find_toolbar.navigate_matches_n_times(3)
60-
first_match_colors = ba.get_all_colors_in_element(first_match)
61-
fourth_match_colors = ba.get_all_colors_in_element(fourth_match)
60+
first_match_colors = browser_actions.get_all_colors_in_element(first_match)
61+
fourth_match_colors = browser_actions.get_all_colors_in_element(fourth_match)
6262

6363
assert len(first_match_colors) < len(fourth_match_colors)
6464
assert are_lists_different(len(first_match_colors), len(fourth_match_colors))

0 commit comments

Comments
 (0)