Skip to content

Commit db54174

Browse files
committed
fixed private window method
1 parent 098d505 commit db54174

File tree

2 files changed

+35
-38
lines changed

2 files changed

+35
-38
lines changed

foxpuppet/windows/browser/panel_ui/panel_ui.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,17 @@ def open_private_window(self) -> None:
108108
lambda _: set(self.selenium.window_handles) - initial_handles,
109109
message="Private window did not open",
110110
)
111-
new_private_window = (
112-
set(self.selenium.window_handles) - initial_handles
113-
).pop()
114-
self.selenium.switch_to.window(new_private_window)
115-
116111
from foxpuppet.windows.browser.window import BrowserWindow
117112

118-
new_window = BrowserWindow(self.selenium, new_private_window)
119-
120-
if not new_window.is_private:
121-
raise ValueError("The new window is not private.")
113+
new_private_window = self.selenium.window_handles[-1]
114+
try:
115+
private_window = BrowserWindow(
116+
self.selenium, new_private_window
117+
).is_private
118+
if private_window:
119+
self.selenium.switch_to.window(new_private_window)
120+
except Exception as e:
121+
raise Exception(f"The new window is not private: {str(e)}")
122122

123123
def open_history_menu(self) -> None:
124124
"""
@@ -172,7 +172,6 @@ def clear_history(self):
172172
""",
173173
self.selenium.find_element(*PanelUILocators.HISTORY_DIALOG_BUTTON),
174174
)
175-
self.selenium.switch_to.default_content()
176175

177176

178177
class PanelUILocators:

tests/test_panel_ui.py

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,10 @@ def test_url_is_present_in_history(browser_history: History, selenium: WebDriver
7272
browser_history.open_history_menu()
7373
history_items = browser_history.history_items()
7474
with selenium.context(selenium.CONTEXT_CHROME):
75-
is_present = False
76-
for item in history_items:
77-
image_attr = item.get_attribute("image")
78-
if image_attr is not None:
79-
is_present = url in image_attr
80-
if is_present:
81-
break
75+
is_present = any(
76+
(image_attr := item.get_attribute("image")) and url in image_attr
77+
for item in history_items
78+
)
8279
assert is_present
8380

8481

@@ -106,13 +103,15 @@ def test_verify_links_open_in_new_tab_from_history(
106103
panel_ui.open_history_menu()
107104
history_items = browser_history.history_items()
108105
with selenium.context(selenium.CONTEXT_CHROME):
109-
found_urls = []
110-
for link in links:
111-
for item in history_items:
112-
image_attr = item.get_attribute("image")
113-
if image_attr is not None and link in image_attr:
114-
found_urls.append(link)
115-
break
106+
found_urls = [
107+
link
108+
for link in links
109+
if any(
110+
image_attr is not None and link in image_attr
111+
for item in history_items
112+
if (image_attr := item.get_attribute("image"))
113+
)
114+
]
116115
assert len(found_urls) == 3
117116

118117

@@ -128,13 +127,15 @@ def test_verify_links_open_in_new_window_from_history(
128127
panel_ui.open_history_menu()
129128
history_items = browser_history.history_items()
130129
with selenium.context(selenium.CONTEXT_CHROME):
131-
found_urls = []
132-
for link in links:
133-
for item in history_items:
134-
image_attr = item.get_attribute("image")
135-
if image_attr is not None and link in image_attr:
136-
found_urls.append(link)
137-
break
130+
found_urls = [
131+
link
132+
for link in links
133+
if any(
134+
image_attr is not None and link in image_attr
135+
for item in history_items
136+
if (image_attr := item.get_attribute("image"))
137+
)
138+
]
138139
assert len(found_urls) == 3
139140

140141

@@ -151,11 +152,8 @@ def test_clear_recent_history(
151152
panel_ui.open_history_menu()
152153
history_items = browser_history.history_items()
153154
with selenium.context(selenium.CONTEXT_CHROME):
154-
is_present = False
155-
for item in history_items:
156-
image_attr = item.get_attribute("image")
157-
if image_attr is not None:
158-
is_present = url in image_attr
159-
if is_present:
160-
break
155+
is_present = any(
156+
(image_attr := item.get_attribute("image")) and url in image_attr
157+
for item in history_items
158+
)
161159
assert not is_present

0 commit comments

Comments
 (0)