Skip to content

Commit

Permalink
Added Private Window Test and Nit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Temidayo32 committed Feb 20, 2025
1 parent fe817cd commit 098d505
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
2 changes: 0 additions & 2 deletions foxpuppet/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.common.action_chains import ActionChains
from foxpuppet.windows import BaseWindow
from foxpuppet.windows.browser.urlbar import UrlBar


class Region(object):
Expand Down Expand Up @@ -41,4 +40,3 @@ def __init__(self, window: BaseWindow, root: WebElement):
self.wait: WebDriverWait = window.wait
self.window: BaseWindow = window
self.actions: ActionChains = ActionChains(self.selenium)
self._url_bar: UrlBar = UrlBar(self.selenium, self.wait)
2 changes: 1 addition & 1 deletion foxpuppet/windows/browser/navbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ def is_tracking_shield_displayed(self) -> bool:
@property
def url_bar(self) -> UrlBar:
"""Returns an instance of the UrlBar class."""
return self._url_bar
return UrlBar(self.window, self.root)
20 changes: 17 additions & 3 deletions foxpuppet/windows/browser/panel_ui/panel_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ def is_update_available(self) -> bool:
bool: True if an update notification (barge) is present, False otherwise.
"""
with self.selenium.context(self.selenium.CONTEXT_CHROME):
barged_status = self.selenium.find_element(
update_status = self.selenium.find_element(
*PanelUILocators.PANEL_UI_BUTTON
).get_attribute("barged")
return barged_status == "true"
return update_status == "true"

def open_panel_menu(self) -> None:
"""
Expand All @@ -78,6 +78,8 @@ def open_new_tab(self) -> None:
lambda _: set(self.selenium.window_handles) - initial_handles,
message="New Tab did not open",
)
new_tab = (set(self.selenium.window_handles) - initial_handles).pop()
self.selenium.switch_to.window(new_tab)

def open_new_window(self) -> None:
"""
Expand All @@ -91,6 +93,8 @@ def open_new_window(self) -> None:
lambda _: set(self.selenium.window_handles) - initial_handles,
message="New window did not open",
)
new_window = (set(self.selenium.window_handles) - initial_handles).pop()
self.selenium.switch_to.window(new_window)

def open_private_window(self) -> None:
"""
Expand All @@ -104,6 +108,17 @@ def open_private_window(self) -> None:
lambda _: set(self.selenium.window_handles) - initial_handles,
message="Private window did not open",
)
new_private_window = (
set(self.selenium.window_handles) - initial_handles
).pop()
self.selenium.switch_to.window(new_private_window)

from foxpuppet.windows.browser.window import BrowserWindow

new_window = BrowserWindow(self.selenium, new_private_window)

if not new_window.is_private:
raise ValueError("The new window is not private.")

def open_history_menu(self) -> None:
"""
Expand Down Expand Up @@ -132,7 +147,6 @@ def history_items(self) -> list[WebElement]:
history_items = self.selenium.find_elements(
*PanelUILocators.RECENT_HISTORY_ITEMS
)
print(history_items)
return history_items

def clear_history(self):
Expand Down
8 changes: 2 additions & 6 deletions foxpuppet/windows/browser/urlbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.support.wait import WebDriverWait
from foxpuppet.region import Region


class UrlBar:
def __init__(self, selenium: WebDriver, wait: WebDriverWait):
self.selenium = selenium
self.wait = wait

class UrlBar(Region):
def suggestions(self, url: str) -> list[str]:
"""
Get all URL suggestions shown in the URL bar.
Expand Down Expand Up @@ -41,7 +38,6 @@ def suggestions(self, url: str) -> list[str]:
for result in search_results
if result.find_element(*URLBarLocators.SEARCH_RESULT_ITEM).text
]
print(suggested_urls)

return suggested_urls

Expand Down
8 changes: 6 additions & 2 deletions tests/test_panel_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ def test_open_new_window(panel_ui: PanelUI, selenium: WebDriver) -> None:
assert len(selenium.window_handles) == 2


def test_open_new_private_window(panel_ui: PanelUI, selenium: WebDriver) -> None:
"""Test opening a new window using the Panel UI."""
panel_ui.open_private_window()
assert len(selenium.window_handles) == 2


def test_url_is_present_in_history(browser_history: History, selenium: WebDriver) -> None:
"""Test that visited URL appears in browser history."""
url = "https://www.mozilla.org/en-US/?v=a"
Expand Down Expand Up @@ -94,7 +100,6 @@ def test_verify_links_open_in_new_tab_from_history(
) -> None:
"""Test that links opened in new tab are present in browser history."""
panel_ui.open_new_tab()
selenium.switch_to.window(selenium.window_handles[-1])
for link in links:
selenium.get(link)
panel_ui.open_panel_menu()
Expand All @@ -116,7 +121,6 @@ def test_verify_links_open_in_new_window_from_history(
) -> None:
"""Test that links opened in new window are present in browser history."""
panel_ui.open_new_window()
selenium.switch_to.window(selenium.window_handles[-1])
time.sleep(3)
for link in links:
selenium.get(link)
Expand Down

0 comments on commit 098d505

Please sign in to comment.