Skip to content
149 changes: 98 additions & 51 deletions modules/browser_object_panel_ui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import random
from time import sleep
from typing import List
from typing import List, Optional, Tuple

from pypom import Region
from selenium.common.exceptions import NoSuchElementException, TimeoutException
Expand Down Expand Up @@ -154,6 +155,31 @@ def open_private_window(self) -> BasePage:
self.get_element("panel-ui-new-private-window").click()
return self

@BasePage.context_chrome
def redirect_to_about_logins_page(self) -> BasePage:
"""
Opens the about:logins page by clicking the Password option in Hamburger Menu"
"""
self.open_panel_menu()
self.get_element("password-button").click()
return self

@BasePage.context_chrome
def reopen_recently_closed_tabs(self) -> BasePage:
"""Reopen all recently closed tabs"""
self.open_panel_menu()
self.click_on("panel-ui-history")

self.click_on("panel-ui-history-recently-closed")
if self.sys_platform() == "Linux":
sleep(2)

self.click_on("panel-ui-history-recently-closed-reopen-tabs")

return self

# History

@BasePage.context_chrome
def open_history_menu(self) -> BasePage:
"""
Expand All @@ -163,19 +189,28 @@ def open_history_menu(self) -> BasePage:
self.click_on("panel-ui-history")
return self

def select_clear_history_option(self, option: str) -> BasePage:
@BasePage.context_chrome
def open_clear_history_dialog(self) -> BasePage:
"""
Selects the clear history option, assumes the history panel is open.
Opens the clear history dialog and switches to iframe context, assuming the history panel is opened
"""
with self.driver.context(self.driver.CONTEXT_CHROME):
self.get_element("clear-recent-history").click()
iframe = self.get_element("iframe")
BrowserActions(self.driver).switch_to_iframe_context(iframe)
self.click_on("clear-recent-history")

with self.driver.context(self.driver.CONTEXT_CONTENT):
dropdown_root = self.get_element("clear-history-dropdown")
dropdown = Dropdown(page=self, root=dropdown_root, require_shadow=False)
dropdown.select_option(option)
# Switch to iframe
self.element_visible("iframe")
iframe = self.get_element("iframe")
BrowserActions(self.driver).switch_to_iframe_context(iframe)
return self

@BasePage.context_content
def select_history_time_range_option(self, option: str) -> BasePage:
"""
Selects time range option (assumes already in iframe context)
"""
dropdown_root = self.get_element("clear-history-dropdown")
dropdown = Dropdown(page=self, root=dropdown_root, require_shadow=False)
dropdown.select_option(option)
return self

def get_all_history(self) -> List[WebElement]:
"""
Expand All @@ -186,14 +221,62 @@ def get_all_history(self) -> List[WebElement]:
return history_items

@BasePage.context_chrome
def redirect_to_about_logins_page(self) -> BasePage:
def verify_most_recent_history_item(self, expected_value: str) -> BasePage:
"""
Opens the about:logins page by clicking the Password option in Hamburger Menu"
Verify that the specified value is the most recent item in the history menu.
Argument:
Expected_value (str): The expected value of the most recent history entry
"""
self.open_panel_menu()
self.get_element("password-button").click()
recent_history_items = self.get_elements("recent-history-content")
actual_value = recent_history_items[0].get_attribute("value")
assert actual_value == expected_value
return self

@BasePage.context_chrome
def get_random_history_entry(self) -> Optional[Tuple[str, str]]:
"""
Retrieve a random browser history entry from the Panel UI.

This method ensures the History submenu is open, fetches all available
history items, selects one at random, extracts its URL and title, and
returns them after validating both are usable.
"""
items = self.get_elements("bookmark-item")

if not items:
return None

item = random.choice(items)
raw_url = item.get_attribute("image")
label = item.get_attribute("label")

trimmed_url = self._extract_url_from_history(raw_url)
assert trimmed_url and label, "History item has missing URL or label."
return trimmed_url, label

def _extract_url_from_history(self, raw_url: str) -> str:
"""
Extract a valid HTTP(S) URL from a raw history image attribute. This method locates the first occurrence of
"http" and returns the substring from there.
Argument:
raw_url (str): The raw string value from the 'image' attribute of a history entry.
"""
if not raw_url:
return ""
if "http" in raw_url:
return raw_url[raw_url.find("http") :]
return raw_url.strip()

@BasePage.context_chrome
def confirm_history_clear(self):
"""
Confirm that the history is empty
"""
self.open_history_menu()
self.expect_element_attribute_contains(
"recent-history-content", "value", "(Empty)"
)

# Bookmarks section

@BasePage.context_chrome
Expand Down Expand Up @@ -268,39 +351,3 @@ def get_bookmark_tags(self, tags: List[str]) -> List[str]:
)
for tag in tags
]

@BasePage.context_chrome
def clear_recent_history(self, execute=True) -> BasePage:
"""Clears recent history. Case of execute=True may not be complete"""
self.open_panel_menu()
self.get_element("panel-ui-history").click()

self.element_exists("clear-recent-history")
self.element_visible("clear-recent-history")
self.element_clickable("clear-recent-history")
if execute:
self.click("clear_recent_history")

return self

@BasePage.context_chrome
def confirm_history_clear(self):
"""Confirm that the history is empty"""
self.open_history_menu()
self.expect_element_attribute_contains(
"recent-history-content", "value", "(Empty)"
)

@BasePage.context_chrome
def reopen_recently_closed_tabs(self) -> BasePage:
"""Reopen all recently closed tabs"""
self.open_panel_menu()
self.click_on("panel-ui-history")

self.click_on("panel-ui-history-recently-closed")
if self.sys_platform() == "Linux":
sleep(2)

self.click_on("panel-ui-history-recently-closed-reopen-tabs")

return self
25 changes: 16 additions & 9 deletions tests/bookmarks_and_history/test_clear_all_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ def test_clear_all_history(driver: Firefox):
"""
C172045: Verify that the user can Clear all the History
"""
gen_page = GenericPage(driver)
panel_ui = PanelUi(driver)
panel_ui.open()
panel_ui.open_history_menu()

panel_ui.select_clear_history_option("Everything")

gen_page.click_on("clear-history-button")
panel_ui.confirm_history_clear()
# Instantiate objects
page = GenericPage(driver)
panel = PanelUi(driver)

# Open Clear History dialog
panel.open_history_menu()
panel.open_clear_history_dialog()

# Select the option to clear all the history
panel.select_history_time_range_option("Everything")
# A method in panel BOM with selectors moved accordingly would make more sense, I'll come to this later,
# there are some context switching + iframe entanglements, couldn't make it work so far
page.click_on("clear-history-button")

# Verify all the history is deleted
panel.confirm_history_clear()
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def test_clear_recent_history_displayed(driver: Firefox):
"""
C172043: Clear recent history panel displayed
"""
panel_ui = PanelUi(driver)
panel_ui.open()
# Instantiate object
panel = PanelUi(driver)

panel_ui.clear_recent_history(execute=False)
# Open Clear recent history dialog
panel.open_history_menu()
panel.open_clear_history_dialog()
42 changes: 17 additions & 25 deletions tests/bookmarks_and_history/test_open_websites_from_history.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import random
import logging

import pytest
from selenium.webdriver import Firefox
Expand All @@ -17,35 +17,27 @@ def use_profile():
return "theme_change"


def trim_url(url: str) -> str:
colon_index = url.find(":")
if colon_index != -1:
return url[colon_index + 1 :].strip()
else:
return ""


def test_open_websites_from_history(driver: Firefox):
"""
C118807: Verify that the user can open websites from the Toolbar History submenu
C118807: Verify that the user can open any random website from Hamburger Menu, History section
"""
panel_ui = PanelUi(driver)
panel_ui.open()
# Instantiate object
panel = PanelUi(driver)

panel_ui.open_history_menu()
# Open History section from Hamburger Menu and get a random entry from browser history
panel.open_history_menu()
result = panel.get_random_history_entry()

with driver.context(driver.CONTEXT_CHROME):
history_items = panel_ui.get_all_history()
if len(history_items) == 0:
assert False, "There is no history."
# Skip test if no history entries are available
if result is None:
logging.info("Test skipped: No history available")
return

rand_index = random.randint(0, len(history_items) - 1)
url_to_visit = history_items[rand_index].get_attribute("image")
website_label = history_items[rand_index].get_attribute("label")
# Extract URL and page title from the selected history entry
url, label = result

trimmed_url = trim_url(url_to_visit)
page = GenericPage(driver, url=trimmed_url)
# Navigate to the selected page and verify it loads correctly
page = GenericPage(driver, url=url)
page.open()

page.url_contains(trimmed_url)
page.title_contains(website_label)
page.url_contains(url)
page.title_contains(label)
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pytest
from selenium.webdriver import Firefox

from modules.browser_object import PanelUi, TabBar
from modules.page_object import GenericPage


@pytest.fixture()
def test_case():
return "118802"


@pytest.fixture()
def use_profile():
return "theme_change"


WIKIPEDIA_URL = "https://www.wikipedia.org/"


def test_the_website_opened_in_new_tab_is_present_in_history_menu(driver: Firefox):
"""
C118802 - Verify that the website opened in new tab is displayed in Hamburger Menu, History section, on top of the
list
"""
# Instantiate objects
tabs = TabBar(driver)
page = GenericPage(driver, url=WIKIPEDIA_URL)
panel = PanelUi(driver)

# Open a desired webpage in a new tab
tabs.open_web_page_in_new_tab(page, 2)
page.url_contains("wikipedia")

# Verify the opened webpage from last step is present in the Hamburger Menu, History section and is on top of the
# list as the most recent website visited
panel.open_history_menu()
panel.verify_most_recent_history_item("Wikipedia")

This file was deleted.

Loading
Loading