Skip to content

Commit

Permalink
fixed private window method
Browse files Browse the repository at this point in the history
  • Loading branch information
Temidayo32 committed Feb 21, 2025
1 parent 098d505 commit db54174
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 38 deletions.
19 changes: 9 additions & 10 deletions foxpuppet/windows/browser/panel_ui/panel_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +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.")
new_private_window = self.selenium.window_handles[-1]
try:
private_window = BrowserWindow(
self.selenium, new_private_window
).is_private
if private_window:
self.selenium.switch_to.window(new_private_window)
except Exception as e:
raise Exception(f"The new window is not private: {str(e)}")

def open_history_menu(self) -> None:
"""
Expand Down Expand Up @@ -172,7 +172,6 @@ def clear_history(self):
""",
self.selenium.find_element(*PanelUILocators.HISTORY_DIALOG_BUTTON),
)
self.selenium.switch_to.default_content()


class PanelUILocators:
Expand Down
54 changes: 26 additions & 28 deletions tests/test_panel_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,10 @@ def test_url_is_present_in_history(browser_history: History, selenium: WebDriver
browser_history.open_history_menu()
history_items = browser_history.history_items()
with selenium.context(selenium.CONTEXT_CHROME):
is_present = False
for item in history_items:
image_attr = item.get_attribute("image")
if image_attr is not None:
is_present = url in image_attr
if is_present:
break
is_present = any(
(image_attr := item.get_attribute("image")) and url in image_attr
for item in history_items
)
assert is_present


Expand Down Expand Up @@ -106,13 +103,15 @@ def test_verify_links_open_in_new_tab_from_history(
panel_ui.open_history_menu()
history_items = browser_history.history_items()
with selenium.context(selenium.CONTEXT_CHROME):
found_urls = []
for link in links:
for item in history_items:
image_attr = item.get_attribute("image")
if image_attr is not None and link in image_attr:
found_urls.append(link)
break
found_urls = [
link
for link in links
if any(
image_attr is not None and link in image_attr
for item in history_items
if (image_attr := item.get_attribute("image"))
)
]
assert len(found_urls) == 3


Expand All @@ -128,13 +127,15 @@ def test_verify_links_open_in_new_window_from_history(
panel_ui.open_history_menu()
history_items = browser_history.history_items()
with selenium.context(selenium.CONTEXT_CHROME):
found_urls = []
for link in links:
for item in history_items:
image_attr = item.get_attribute("image")
if image_attr is not None and link in image_attr:
found_urls.append(link)
break
found_urls = [
link
for link in links
if any(
image_attr is not None and link in image_attr
for item in history_items
if (image_attr := item.get_attribute("image"))
)
]
assert len(found_urls) == 3


Expand All @@ -151,11 +152,8 @@ def test_clear_recent_history(
panel_ui.open_history_menu()
history_items = browser_history.history_items()
with selenium.context(selenium.CONTEXT_CHROME):
is_present = False
for item in history_items:
image_attr = item.get_attribute("image")
if image_attr is not None:
is_present = url in image_attr
if is_present:
break
is_present = any(
(image_attr := item.get_attribute("image")) and url in image_attr
for item in history_items
)
assert not is_present

0 comments on commit db54174

Please sign in to comment.