@@ -50,42 +50,80 @@ def open_panel_menu(self) -> None:
5050 with self .selenium .context (self .selenium .CONTEXT_CHROME ):
5151 self .selenium .find_element (* PanelUILocators .PANEL_UI_BUTTON ).click ()
5252
53+ def open_new_tab (self ) -> None :
54+ """
55+ Opens a new tab using the Panel UI menu.
56+ """
57+ self .open_panel_menu ()
58+ with self .selenium .context (self .selenium .CONTEXT_CHROME ):
59+ self .selenium .find_element (* PanelUILocators .NEW_TAB ).click ()
60+
61+ def open_new_window (self ) -> None :
62+ """
63+ Opens a new window using the Panel UI menu.
64+ """
65+ self .open_panel_menu ()
66+ with self .selenium .context (self .selenium .CONTEXT_CHROME ):
67+ self .selenium .find_element (* PanelUILocators .NEW_WINDOW ).click ()
68+
5369 def open_private_window (self ) -> None :
5470 """
5571 Opens a new window in private browsing mode using the Panel UI menu.
5672 """
57- # self.open_panel_menu()
73+ self .open_panel_menu ()
5874 with self .selenium .context (self .selenium .CONTEXT_CHROME ):
5975 self .selenium .find_element (* PanelUILocators .PRIVATE_WINDOW ).click ()
6076
6177 def open_history_menu (self ) -> None :
6278 """
6379 Opens the History in Panel UI Menu
6480 """
65- # self.open_panel_menu()
81+ self .open_panel_menu ()
6682 with self .selenium .context (self .selenium .CONTEXT_CHROME ):
6783 self .selenium .find_element (* PanelUILocators .HISTORY ).click ()
6884
69- def wait_for_num_windows_or_tabs (self , expected_count : int ) -> None :
85+ def wait_for_num_windows_or_tabs (self , expected_count : int ) -> bool :
7086 """
7187 Waits until the number of open browser windows or tabs matches the expected value.
7288
7389 Args:
7490 expected_count (int): The expected number of windows or tabs.
7591 """
7692 self .wait .until (
77- lambda _ : len (self .driver .window_handles ) == expected_count ,
78- f"Expected { expected_count } windows or tabs, but found { len (self .driver .window_handles )} " ,
93+ lambda _ : len (self .selenium .window_handles ) == expected_count ,
94+ f"Expected { expected_count } windows or tabs, but found { len (self .selenium .window_handles )} " ,
7995 )
96+ return True
8097
8198 def switch_to_new_window_or_tab (self ) -> None :
8299 """Get list of all window handles, switch to the newly opened tab/window"""
83100 handles = self .selenium .window_handles
84101 self .selenium .switch_to .window (handles [- 1 ])
85102
103+ def awesome_bar (self , links : list ) -> list :
104+ """Check if the provided links are present in the awesome bar's suggestion links."""
105+ urls = []
106+ with self .selenium .context (self .selenium .CONTEXT_CHROME ):
107+ for link in links :
108+ awesome_bar = self .selenium .find_element (* PanelUILocators .INPUT_FIELD )
109+ awesome_bar .clear ()
110+ awesome_bar .send_keys (link )
111+
112+ self .wait .until (
113+ lambda _ : self .selenium .find_elements (* PanelUILocators .SEARCH_RESULTS )
114+ )
115+
116+ search_results = self .selenium .find_elements (
117+ * PanelUILocators .SEARCH_RESULT_ITEMS
118+ )
86119
87- class History (PanelUI ):
88- """Handles interactions with Firefox History."""
120+ for result in search_results :
121+ url_span = result .find_element (* PanelUILocators .SEARCH_RESULT_ITEM )
122+ if url_span .text in link :
123+ if len (url_span .text ) != 0 :
124+ urls .append (link )
125+ break
126+ return urls
89127
90128 def is_present (self , link : str ) -> bool :
91129 """
@@ -132,9 +170,23 @@ def clear_history(self):
132170 )
133171 self .selenium .switch_to .default_content ()
134172
173+ def verify_links_in_awesome_bar (self , links : list , new_window : bool = False ) -> list :
174+ """
175+ Verifies that the provided links appear in the awesome bar.
176+ Args:
177+ links `list`: A list of links to be verified.
135178
136- class PrivateWindow (PanelUI ):
137- """Handles interactions with Firefox Private Window."""
179+ Returns:
180+ list: A list of links that were not found in the awesome bar.
181+ """
182+ if new_window :
183+ self .open_new_window ()
184+ else :
185+ self .open_new_tab ()
186+ self .switch_to_new_window_or_tab ()
187+ for link in links :
188+ self .selenium .get (link )
189+ return self .awesome_bar (links )
138190
139191 def verify_private_browsing_links_not_in_awesome_bar (self , links : list ) -> list :
140192 """
@@ -145,36 +197,43 @@ def verify_private_browsing_links_not_in_awesome_bar(self, links: list) -> list:
145197 Returns:
146198 list: A list of links that appeared in the awesome bar during private browsing.
147199 """
148- invalid_links = []
149- initial_window_handle = self .driver .current_window_handle
150- # self.open_private_window()
200+ initial_window_handle = self .selenium .current_window_handle
201+ self .open_private_window ()
151202 self .switch_to_new_window_or_tab ()
152203
153204 for link in links :
154205 self .selenium .get (link )
155206
156- self .driver .switch_to .window (initial_window_handle )
157-
158- with self .selenium .context (self .selenium .CONTEXT_CHROME ):
159- for link in links :
160- awesome_bar = self .selenium .find_element (* PanelUILocators .INPUT_FIELD )
161- awesome_bar .clear ()
162- awesome_bar .send_keys (link )
163-
164- self .wait .until (
165- lambda _ : self .selenium .find_elements (* PanelUILocators .SEARCH_RESULTS )
166- )
207+ self .selenium .switch_to .window (initial_window_handle )
208+ return self .awesome_bar (links )
167209
168- search_results = self . selenium . find_elements (
169- * PanelUILocators . SEARCH_RESULTS
170- )
171- if any ( link in result . text for result in search_results ) :
172- invalid_links . append ( link )
210+ def verify_links_in_history ( self , links : list , new_window : bool = False ) -> list :
211+ """
212+ Verifies that the provided links appear in the history.
213+ Args :
214+ links `list`: A list of links to be verified.
173215
174- return invalid_links
216+ Returns:
217+ list: A list of links that were not found in the history.
218+ """
219+ if new_window :
220+ self .open_new_window ()
221+ else :
222+ self .open_new_tab ()
223+ self .switch_to_new_window_or_tab ()
224+ for link in links :
225+ self .selenium .get (link )
226+ self .open_panel_menu ()
227+ self .open_history_menu ()
228+ urls = []
229+ for link in links :
230+ if not self .is_present (link ):
231+ urls .append (link )
232+ return urls
175233
176234 def verify_private_browsing_links_not_in_history (
177- self , links : list , history : History
235+ self ,
236+ links : list ,
178237 ) -> list :
179238 """
180239 Verifies that the provided links visited in private browsing session do not appear in the history.
@@ -186,8 +245,8 @@ def verify_private_browsing_links_not_in_history(
186245 list: A list of links that were found in the history during the private browsing session.
187246 """
188247 invalid_links = []
189- initial_window_handle = self .driver .current_window_handle
190- # self.open_private_window()
248+ initial_window_handle = self .selenium .current_window_handle
249+ self .open_private_window ()
191250 self .switch_to_new_window_or_tab ()
192251
193252 for link in links :
@@ -197,15 +256,18 @@ def verify_private_browsing_links_not_in_history(
197256 self .open_panel_menu ()
198257 self .open_history_menu ()
199258 for link in links :
200- if history .is_present (link ):
259+ if self .is_present (link ):
201260 invalid_links .append (link )
202261 return invalid_links
203262
204263
205264class PanelUILocators :
206265 PANEL_UI_BUTTON = (By .ID , "PanelUI-menu-button" )
266+ NEW_TAB = (By .ID , "appMenu-new-tab-button2" )
267+ NEW_WINDOW = (By .ID , "appMenu-new-window-button2" )
207268 PRIVATE_WINDOW = (By .ID , "appMenu-new-private-window-button2" )
208269 HISTORY = (By .ID , "appMenu-history-button" )
270+ INPUT_FIELD = (By .ID , "urlbar-input" )
209271 CLEAR_RECENT_HISTORY = (By .ID , "appMenuClearRecentHistory" )
210272 CLEAR_RECENT_HISTORY_BUTTON = (By .CSS_SELECTOR , "button[dlgtype='accept']" )
211273 CLEAR_HISTORY_EVERYTHING = (By .CSS_SELECTOR , "menuitem[value='0']" )
@@ -216,10 +278,11 @@ class PanelUILocators:
216278 "#appMenu_historyMenu toolbarbutton.subviewbutton" ,
217279 )
218280 HISTORY_IFRAME = (By .CSS_SELECTOR , "browser.dialogFrame" )
281+ SEARCH_RESULTS = (By .ID , "urlbar-results" )
282+ SEARCH_RESULT_ITEMS = (By .CSS_SELECTOR , "div.urlbarView-row[role='presentation']" )
283+ SEARCH_RESULT_ITEM = (By .CSS_SELECTOR , "span.urlbarView-url" )
219284
220285
221286PANEL_ITEMS = {
222287 "PanelUI-menu-button" : PanelUI ,
223- "appMenu-history-button" : History ,
224- "appMenu-new-private-window-button2" : PrivateWindow ,
225288}
0 commit comments