Skip to content

Commit c7c33d6

Browse files
committed
Refactor clear history tests
1 parent 607c70a commit c7c33d6

File tree

3 files changed

+39
-35
lines changed

3 files changed

+39
-35
lines changed

modules/browser_object_panel_ui.py

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,27 @@ def open_history_menu(self) -> BasePage:
163163
self.click_on("panel-ui-history")
164164
return self
165165

166-
def select_clear_history_option(self, option: str) -> BasePage:
166+
@BasePage.context_chrome
167+
def open_clear_history_dialog(self) -> BasePage:
168+
"""Opens the clear history dialog and switches to iframe context"""
169+
self.open_history_menu()
170+
self.element_clickable("clear-recent-history")
171+
self.click_on("clear-recent-history")
172+
173+
self.element_visible("iframe")
174+
iframe = self.get_element("iframe")
175+
BrowserActions(self.driver).switch_to_iframe_context(iframe)
176+
return self
177+
178+
@BasePage.context_content
179+
def select_history_time_range_option(self, option: str) -> BasePage:
167180
"""
168-
Selects the clear history option, assumes the history panel is open.
181+
Selects time range option (assumes already in iframe context)
169182
"""
170-
with self.driver.context(self.driver.CONTEXT_CHROME):
171-
self.get_element("clear-recent-history").click()
172-
iframe = self.get_element("iframe")
173-
BrowserActions(self.driver).switch_to_iframe_context(iframe)
174-
175-
with self.driver.context(self.driver.CONTEXT_CONTENT):
176-
dropdown_root = self.get_element("clear-history-dropdown")
177-
dropdown = Dropdown(page=self, root=dropdown_root, require_shadow=False)
178-
dropdown.select_option(option)
183+
dropdown_root = self.get_element("clear-history-dropdown")
184+
dropdown = Dropdown(page=self, root=dropdown_root, require_shadow=False)
185+
dropdown.select_option(option)
186+
return self
179187

180188
def get_all_history(self) -> List[WebElement]:
181189
"""
@@ -269,20 +277,6 @@ def get_bookmark_tags(self, tags: List[str]) -> List[str]:
269277
for tag in tags
270278
]
271279

272-
@BasePage.context_chrome
273-
def clear_recent_history(self, execute=True) -> BasePage:
274-
"""Clears recent history. Case of execute=True may not be complete"""
275-
self.open_panel_menu()
276-
self.get_element("panel-ui-history").click()
277-
278-
self.element_exists("clear-recent-history")
279-
self.element_visible("clear-recent-history")
280-
self.element_clickable("clear-recent-history")
281-
if execute:
282-
self.click("clear_recent_history")
283-
284-
return self
285-
286280
@BasePage.context_chrome
287281
def confirm_history_clear(self):
288282
"""Confirm that the history is empty"""

tests/bookmarks_and_history/test_clear_all_history.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@ def test_clear_all_history(driver: Firefox):
1919
"""
2020
C172045: Verify that the user can Clear all the History
2121
"""
22-
gen_page = GenericPage(driver)
23-
panel_ui = PanelUi(driver)
24-
panel_ui.open()
25-
panel_ui.open_history_menu()
2622

27-
panel_ui.select_clear_history_option("Everything")
23+
# Instantiate objects
24+
page = GenericPage(driver)
25+
panel = PanelUi(driver)
2826

29-
gen_page.click_on("clear-history-button")
30-
panel_ui.confirm_history_clear()
27+
# Open Clear History menu
28+
panel.open_clear_history_dialog()
29+
30+
# Select the option to clear all the history
31+
panel.select_history_time_range_option("Everything")
32+
# A method in panel-ui with selectors moved accordingly would work better, limited for now due to context level
33+
# set to chrome context while shadow parent needs content context
34+
page.click_on("clear-history-button")
35+
36+
# Verify all the history is deleted
37+
panel.confirm_history_clear()

tests/bookmarks_and_history/test_clear_recent_history_displayed.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ def test_clear_recent_history_displayed(driver: Firefox):
1313
"""
1414
C172043: Clear recent history panel displayed
1515
"""
16-
panel_ui = PanelUi(driver)
17-
panel_ui.open()
1816

19-
panel_ui.clear_recent_history(execute=False)
17+
# Instantiate object
18+
panel = PanelUi(driver)
19+
20+
# Open Clear recent history dialog
21+
panel.open()
22+
panel.open_clear_history_dialog()

0 commit comments

Comments
 (0)