Skip to content

Commit 1971f95

Browse files
authored
Merge pull request #559 from mozilla/as/refactor-bookmark-history-suite
Anca/Bookmarks refactoring - star icon and hamburger menu (first part) [Tracy] Landing on Anca's behalf, since she is out and we want to get this landed before Beta1
2 parents 48f5c8d + 8a1d633 commit 1971f95

13 files changed

+142
-109
lines changed

modules/browser_object_navigation.py

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,77 @@ def open_tracker_panel(self) -> BasePage:
256256
self.get_element("shield-icon").click()
257257
return self
258258

259+
def wait_for_item_to_download(self, filename: str) -> BasePage:
260+
"""
261+
Check the downloads tool in the toolbar to wait for a given file to download
262+
"""
263+
original_timeout = self.driver.timeouts.implicit_wait
264+
try:
265+
# Whatever our timeout, we want to lengthen it because downloads
266+
self.driver.implicitly_wait(original_timeout * 2)
267+
self.element_visible("downloads-item-by-file", labels=[filename])
268+
self.expect_not(
269+
EC.element_attribute_to_include(
270+
self.get_selector("downloads-button"), "animate"
271+
)
272+
)
273+
with self.driver.context(self.context_id):
274+
self.driver.execute_script(
275+
"arguments[0].setAttribute('hidden', true)",
276+
self.get_element("downloads-button"),
277+
)
278+
finally:
279+
self.driver.implicitly_wait(original_timeout)
280+
return self
281+
282+
@BasePage.context_chrome
283+
def refresh_page(self) -> BasePage:
284+
"""
285+
Refreshes the current page by clicking the refresh button in the browser.
286+
"""
287+
288+
self.get_element("refresh-button").click()
289+
self.wait_for_page_to_load()
290+
return self
291+
292+
def handle_geolocation_prompt(self, button_type="primary"):
293+
"""
294+
Handles geolocation prompt by clicking either the 'Allow' or 'Block' button based on the button_type provided
295+
"""
296+
button_selector = f"popup-notification-{button_type}-button"
297+
self.element_clickable(button_selector)
298+
self.click_on(button_selector)
299+
300+
def open_searchmode_switcher_settings(self):
301+
"""Open search settings from searchmode switcher in awesome bar"""
302+
self.click_on("searchmode-switcher")
303+
self.click_on("searchmode-switcher-settings")
304+
return self
305+
306+
@BasePage.context_chrome
307+
def select_element_in_nav(self, element: str) -> BasePage:
308+
self.get_element(element).click()
309+
return self
310+
311+
# Bookmark
312+
313+
@BasePage.context_chrome
314+
def add_bookmark_via_star_icon(self) -> BasePage:
315+
"""
316+
Bookmark a site via star button and click save on the bookmark panel
317+
"""
318+
self.get_element("star-button").click()
319+
self.get_element("save-bookmark-button").click()
320+
return self
321+
322+
@BasePage.context_chrome
323+
def verify_star_button_is_blue(self) -> BasePage:
324+
"""
325+
Verifies that the star button is blue (indicating a bookmarked page)
326+
"""
327+
self.element_visible("blue-star-button")
328+
return self
329+
259330
@BasePage.context_chrome
260331
def bookmark_page_other(self) -> BasePage:
261332
self.get_element("star-button").click()
@@ -289,25 +360,6 @@ def add_bookmark_advanced(
289360
ba.switch_to_content_context()
290361
return self
291362

292-
@BasePage.context_chrome
293-
def add_bookmark_via_star(self) -> BasePage:
294-
"""
295-
Bookmark a site via star button and click save on the bookmark panel
296-
"""
297-
self.get_element("star-button").click()
298-
self.get_element("save-bookmark-button").click()
299-
return self
300-
301-
@BasePage.context_chrome
302-
def add_bookmark_via_menu(self) -> BasePage:
303-
"""
304-
Bookmark a site via bookmarks menu and click save on the bookmark panel
305-
"""
306-
307-
self.get_element("bookmark-current-tab").click()
308-
self.get_element("save-bookmark-button").click()
309-
return self
310-
311363
@BasePage.context_chrome
312364
def toggle_bookmarks_toolbar_with_key_combo(self) -> BasePage:
313365
"""Use Cmd/Ctrl + B to open the Print Preview, wait for load"""
@@ -319,29 +371,6 @@ def toggle_bookmarks_toolbar_with_key_combo(self) -> BasePage:
319371
self.perform_key_combo(mod_key, Keys.SHIFT, "b")
320372
return self
321373

322-
def wait_for_item_to_download(self, filename: str) -> BasePage:
323-
"""
324-
Check the downloads tool in the toolbar to wait for a given file to download
325-
"""
326-
original_timeout = self.driver.timeouts.implicit_wait
327-
try:
328-
# Whatever our timeout, we want to lengthen it because downloads
329-
self.driver.implicitly_wait(original_timeout * 2)
330-
self.element_visible("downloads-item-by-file", labels=[filename])
331-
self.expect_not(
332-
EC.element_attribute_to_include(
333-
self.get_selector("downloads-button"), "animate"
334-
)
335-
)
336-
with self.driver.context(self.context_id):
337-
self.driver.execute_script(
338-
"arguments[0].setAttribute('hidden', true)",
339-
self.get_element("downloads-button"),
340-
)
341-
finally:
342-
self.driver.implicitly_wait(original_timeout)
343-
return self
344-
345374
@BasePage.context_chrome
346375
def confirm_bookmark_exists(self, match_string: str) -> BasePage:
347376
"""
@@ -361,32 +390,3 @@ def confirm_bookmark_exists(self, match_string: str) -> BasePage:
361390
)
362391
assert matches_short_string or matches_long_string
363392
return self
364-
365-
@BasePage.context_chrome
366-
def refresh_page(self) -> BasePage:
367-
"""
368-
Refreshes the current page by clicking the refresh button in the browser.
369-
"""
370-
371-
self.get_element("refresh-button").click()
372-
self.wait_for_page_to_load()
373-
return self
374-
375-
def handle_geolocation_prompt(self, button_type="primary"):
376-
"""
377-
Handles geolocation prompt by clicking either the 'Allow' or 'Block' button based on the button_type provided
378-
"""
379-
button_selector = f"popup-notification-{button_type}-button"
380-
self.element_clickable(button_selector)
381-
self.click_on(button_selector)
382-
383-
def open_searchmode_switcher_settings(self):
384-
"""Open search settings from searchmode switcher in awesome bar"""
385-
self.click_on("searchmode-switcher")
386-
self.click_on("searchmode-switcher-settings")
387-
return self
388-
389-
@BasePage.context_chrome
390-
def select_element_in_nav(self, element: str) -> BasePage:
391-
self.get_element(element).click()
392-
return self

modules/browser_object_panel_ui.py

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
from pypom import Region
44
from selenium.common.exceptions import NoSuchElementException, TimeoutException
5+
from selenium.webdriver import Firefox
56
from selenium.webdriver.remote.webelement import WebElement
67
from selenium.webdriver.support import expected_conditions as EC
78

9+
from modules.browser_object_navigation import Navigation
810
from modules.components.dropdown import Dropdown
911
from modules.page_base import BasePage
1012
from modules.util import BrowserActions, PomUtils
@@ -15,6 +17,10 @@ class PanelUi(BasePage):
1517

1618
URL_TEMPLATE = "about:blank"
1719

20+
def __init__(self, driver: Firefox, **kwargs):
21+
super().__init__(driver, **kwargs)
22+
self.navigation = Navigation(self.driver)
23+
1824
class Menu(Region):
1925
"""
2026
PyPOM Region factory for the PanelUi Dropdown menu
@@ -153,15 +159,6 @@ def open_history_menu(self) -> BasePage:
153159
self.get_element("panel-ui-history").click()
154160
return self
155161

156-
def open_bookmarks_menu(self) -> BasePage:
157-
"""
158-
Opens the Bookmarks menu
159-
"""
160-
self.open_panel_menu()
161-
with self.driver.context(self.driver.CONTEXT_CHROME):
162-
self.get_element("panel-ui-bookmarks").click()
163-
return self
164-
165162
def select_clear_history_option(self, option: str) -> BasePage:
166163
"""
167164
Selects the clear history option, assumes the history panel is open.
@@ -192,3 +189,35 @@ def redirect_to_about_logins_page(self) -> BasePage:
192189
with self.driver.context(self.driver.CONTEXT_CHROME):
193190
self.get_element("password-button").click()
194191
return self
192+
193+
# Bookmarks section
194+
195+
@BasePage.context_chrome
196+
def open_bookmarks_panel_from_hamburger_menu(self) -> BasePage:
197+
"""
198+
Opens the Bookmarks panel from the Hamburger Menu
199+
"""
200+
self.open_panel_menu()
201+
with self.driver.context(self.driver.CONTEXT_CHROME):
202+
self.get_element("panel-ui-bookmarks").click()
203+
return self
204+
205+
@BasePage.context_chrome
206+
def bookmark_current_tab_via_hamburger_menu(self) -> BasePage:
207+
"""
208+
Opens the Bookmarks panel from the Hamburger Menu, selects Bookmarks the current tab.. and clicks
209+
Save button from Add Bookmark in Address bar "
210+
"""
211+
self.get_element("bookmark-current-tab").click()
212+
self.navigation.get_element("save-bookmark-button").click()
213+
return self
214+
215+
@BasePage.context_chrome
216+
def verify_bookmark_exists_in_hamburger_menu(self, bookmark_title: str) -> BasePage:
217+
"""
218+
Verifies that a bookmark with the specified title exists inside Bookmark section from Hamburger menu
219+
Arguments:
220+
bookmark_title (str): The title text to look for in the bookmark
221+
"""
222+
self.element_visible("bookmark-by-title", labels=[bookmark_title])
223+
return self

modules/data/navigation.components.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
},
172172

173173
"firefox-suggest": {
174+
"doNotCache": true,
174175
"selectorData": "div.urlbarView-row[label='Firefox Suggest'] > span.urlbarView-row-inner",
175176
"strategy": "css",
176177
"groups": []

tests/address_bar_and_search/test_preferences_all_toggles_enabled.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_preferences_all_toggles_enabled(driver: Firefox):
1717
"""
1818
C1618400: Preferences - All toggles buttons Enabled
1919
"""
20-
# instantiate objects
20+
# Instantiate objects
2121
nav = Navigation(driver)
2222
about_prefs = AboutPrefs(driver, category="search")
2323
about_prefs.open()
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22
from selenium.webdriver import Firefox
33

4-
from modules.browser_object_navigation import Navigation
54
from modules.browser_object_panel_ui import PanelUi
65

76

@@ -11,21 +10,23 @@ def test_case():
1110

1211

1312
URL_TO_BOOKMARK = "https://www.mozilla.org/"
13+
BOOKMARK_TITLE = "Internet for people"
1414

1515

16-
def test_bookmark_via_bookmark_menu(driver: Firefox):
16+
def test_bookmark_via_hamburger_menu(driver: Firefox):
1717
"""
18-
C2084489: Verify that the user can Bookmark a page from the Bookmarks menu
18+
C2084489: Verify that the user can bookmark a page using Bookmark current tab .. opened from Hamburger Menu
1919
"""
20-
# instantiate object
21-
nav = Navigation(driver)
20+
# Instantiate object
2221
panel = PanelUi(driver)
2322

24-
# Bookmark the given website via bookmarks menu
23+
# Navigate to test website
2524
driver.get(URL_TO_BOOKMARK)
26-
panel.open_bookmarks_menu()
27-
nav.add_bookmark_via_menu()
2825

29-
# Verify that the bookmark is displayed in bookmarks menu
30-
panel.open_bookmarks_menu()
31-
panel.element_visible("bookmark-by-title", labels=["Internet for people"])
26+
# Bookmark using Bookmark current tab option from Hamburger Menu
27+
panel.open_bookmarks_panel_from_hamburger_menu()
28+
panel.bookmark_current_tab_via_hamburger_menu()
29+
30+
# Verify bookmark appears in Hamburger Menu, Bookmarks section
31+
panel.open_bookmarks_panel_from_hamburger_menu()
32+
panel.verify_bookmark_exists_in_hamburger_menu(BOOKMARK_TITLE)

tests/bookmarks_and_history/test_bookmark_website_via_star_button.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,25 @@ def test_case():
1111

1212

1313
URL_TO_BOOKMARK = "https://www.mozilla.org/"
14+
BOOKMARK_TITLE = "Internet for people"
1415

1516

1617
@pytest.mark.ci
1718
def test_bookmark_website_via_star(driver: Firefox):
1819
"""
1920
C2084539: Verify that the Websites can be bookmarked via star-shaped button
2021
"""
21-
# instantiate object
22+
# Instantiate object
2223
nav = Navigation(driver)
2324
panel = PanelUi(driver)
2425

25-
# Bookmark the given website and check the bookmark star turned blue
26+
# Navigate to test website
2627
driver.get(URL_TO_BOOKMARK)
27-
nav.add_bookmark_via_star()
28-
with driver.context(driver.CONTEXT_CHROME):
29-
nav.element_visible("blue-star-button")
3028

31-
# Verify that the bookmark is displayed in bookmarks menu
32-
panel.open_bookmarks_menu()
33-
panel.element_visible("bookmark-by-title", labels=["Internet for people"])
29+
# Bookmark using star button and verify star turned blue
30+
nav.add_bookmark_via_star_icon()
31+
nav.verify_star_button_is_blue()
32+
33+
# Verify bookmark appears in Hamburger Menu, Bookmarks section
34+
panel.open_bookmarks_panel_from_hamburger_menu()
35+
panel.verify_bookmark_exists_in_hamburger_menu(BOOKMARK_TITLE)

tests/bookmarks_and_history/test_delete_bookmarks_from_toolbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_delete_bookmarks_from_toolbar(driver: Firefox):
2626

2727
# Bookmark the given website via star button
2828
driver.get(URL_TO_BOOKMARK)
29-
nav.add_bookmark_via_star()
29+
nav.add_bookmark_via_star_icon()
3030

3131
with driver.context(driver.CONTEXT_CHROME):
3232
# Verify that the bookmark is added

tests/bookmarks_and_history/test_edit_bookmark_from_bookmark_menu.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ def test_edit_bookmark_from_bookmark_menu(driver: Firefox):
2828

2929
# Bookmark the given website via bookmarks menu
3030
GenericPage(driver, url=URL_TO_BOOKMARK).open()
31-
panel.open_bookmarks_menu()
32-
nav.add_bookmark_via_menu()
31+
panel.open_bookmarks_panel_from_hamburger_menu()
32+
nav.add_bookmark_via_star_icon()
3333

3434
with driver.context(driver.CONTEXT_CHROME):
3535
# enable add a tag to a bookmark in the bookmark panel
3636
driver.execute_script(ENABLE_ADD_TAG)
3737

3838
# Open the Hamburger menu, click on the Edit This Bookmark button from the Bookmarks section
39-
panel.open_bookmarks_menu()
39+
panel.open_bookmarks_panel_from_hamburger_menu()
4040
panel.get_element("bookmark-current-tab").click()
4141

4242
# Change bookmark name, location and add a tag

tests/bookmarks_and_history/test_edit_bookmark_via_star_button.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_edit_bookmark_via_star_button(driver: Firefox):
2525

2626
# Bookmark the given website via star button
2727
GenericPage(driver, url=URL_TO_EDIT).open()
28-
nav.add_bookmark_via_star()
28+
nav.add_bookmark_via_star_icon()
2929

3030
# Open the edit bookmark panel and change bookmark name and location
3131
with driver.context(driver.CONTEXT_CHROME):

tests/bookmarks_and_history/test_open_all_bookmarks_from_bookmarks_toolbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_open_all_bookmarks_from_bookmarks_toolbar(driver: Firefox):
3232
urls_to_bookmark = [URL1_TO_BOOKMARK, URL2_TO_BOOKMARK, URL3_TO_BOOKMARK]
3333
for url in urls_to_bookmark:
3434
GenericPage(driver, url=url).open()
35-
nav.add_bookmark_via_star()
35+
nav.add_bookmark_via_star_icon()
3636

3737
# Load a page that we didn't bookmark, so we can ensure that we're not just picking up on that instance of the page
3838
GenericPage(driver, url=URL_NOT_BOOKMARKED).open()

0 commit comments

Comments
 (0)