1+ import  random 
12from  time  import  sleep 
2- from  typing  import  List 
3+ from  typing  import  List ,  Optional ,  Tuple 
34
45from  pypom  import  Region 
56from  selenium .common .exceptions  import  NoSuchElementException , TimeoutException 
@@ -154,6 +155,31 @@ def open_private_window(self) -> BasePage:
154155            self .get_element ("panel-ui-new-private-window" ).click ()
155156        return  self 
156157
158+     @BasePage .context_chrome  
159+     def  redirect_to_about_logins_page (self ) ->  BasePage :
160+         """ 
161+         Opens the about:logins page by clicking the Password option in Hamburger Menu" 
162+         """ 
163+         self .open_panel_menu ()
164+         self .get_element ("password-button" ).click ()
165+         return  self 
166+ 
167+     @BasePage .context_chrome  
168+     def  reopen_recently_closed_tabs (self ) ->  BasePage :
169+         """Reopen all recently closed tabs""" 
170+         self .open_panel_menu ()
171+         self .click_on ("panel-ui-history" )
172+ 
173+         self .click_on ("panel-ui-history-recently-closed" )
174+         if  self .sys_platform () ==  "Linux" :
175+             sleep (2 )
176+ 
177+         self .click_on ("panel-ui-history-recently-closed-reopen-tabs" )
178+ 
179+         return  self 
180+ 
181+     # History 
182+ 
157183    @BasePage .context_chrome  
158184    def  open_history_menu (self ) ->  BasePage :
159185        """ 
@@ -163,19 +189,28 @@ def open_history_menu(self) -> BasePage:
163189        self .click_on ("panel-ui-history" )
164190        return  self 
165191
166-     def  select_clear_history_option (self , option : str ) ->  BasePage :
192+     @BasePage .context_chrome  
193+     def  open_clear_history_dialog (self ) ->  BasePage :
167194        """ 
168-         Selects  the clear history option, assumes  the history panel is open.  
195+         Opens  the clear history dialog and switches to iframe context, assuming  the history panel is opened  
169196        """ 
170-         with  self .driver .context (self .driver .CONTEXT_CHROME ):
171-             self .get_element ("clear-recent-history" ).click ()
172-             iframe  =  self .get_element ("iframe" )
173-             BrowserActions (self .driver ).switch_to_iframe_context (iframe )
197+         self .click_on ("clear-recent-history" )
174198
175-             with  self .driver .context (self .driver .CONTEXT_CONTENT ):
176-                 dropdown_root  =  self .get_element ("clear-history-dropdown" )
177-                 dropdown  =  Dropdown (page = self , root = dropdown_root , require_shadow = False )
178-                 dropdown .select_option (option )
199+         # Switch to iframe 
200+         self .element_visible ("iframe" )
201+         iframe  =  self .get_element ("iframe" )
202+         BrowserActions (self .driver ).switch_to_iframe_context (iframe )
203+         return  self 
204+ 
205+     @BasePage .context_content  
206+     def  select_history_time_range_option (self , option : str ) ->  BasePage :
207+         """ 
208+         Selects time range option (assumes already in iframe context) 
209+         """ 
210+         dropdown_root  =  self .get_element ("clear-history-dropdown" )
211+         dropdown  =  Dropdown (page = self , root = dropdown_root , require_shadow = False )
212+         dropdown .select_option (option )
213+         return  self 
179214
180215    def  get_all_history (self ) ->  List [WebElement ]:
181216        """ 
@@ -186,14 +221,62 @@ def get_all_history(self) -> List[WebElement]:
186221            return  history_items 
187222
188223    @BasePage .context_chrome  
189-     def  redirect_to_about_logins_page (self ) ->  BasePage :
224+     def  verify_most_recent_history_item (self ,  expected_value :  str ) ->  BasePage :
190225        """ 
191-         Opens the about:logins page by clicking the Password option in Hamburger Menu" 
226+         Verify that the specified value is the most recent item in the history menu. 
227+         Argument: 
228+             Expected_value (str): The expected value of the most recent history entry 
192229        """ 
193-         self .open_panel_menu ()
194-         self .get_element ("password-button" ).click ()
230+         recent_history_items  =  self .get_elements ("recent-history-content" )
231+         actual_value  =  recent_history_items [0 ].get_attribute ("value" )
232+         assert  actual_value  ==  expected_value 
195233        return  self 
196234
235+     @BasePage .context_chrome  
236+     def  get_random_history_entry (self ) ->  Optional [Tuple [str , str ]]:
237+         """ 
238+         Retrieve a random browser history entry from the Panel UI. 
239+ 
240+         This method ensures the History submenu is open, fetches all available 
241+         history items, selects one at random, extracts its URL and title, and 
242+         returns them after validating both are usable. 
243+         """ 
244+         items  =  self .get_elements ("bookmark-item" )
245+ 
246+         if  not  items :
247+             return  None 
248+ 
249+         item  =  random .choice (items )
250+         raw_url  =  item .get_attribute ("image" )
251+         label  =  item .get_attribute ("label" )
252+ 
253+         trimmed_url  =  self ._extract_url_from_history (raw_url )
254+         assert  trimmed_url  and  label , "History item has missing URL or label." 
255+         return  trimmed_url , label 
256+ 
257+     def  _extract_url_from_history (self , raw_url : str ) ->  str :
258+         """ 
259+         Extract a valid HTTP(S) URL from a raw history image attribute. This method locates the first occurrence of 
260+         "http" and returns the substring from there. 
261+         Argument: 
262+             raw_url (str): The raw string value from the 'image' attribute of a history entry. 
263+         """ 
264+         if  not  raw_url :
265+             return  "" 
266+         if  "http"  in  raw_url :
267+             return  raw_url [raw_url .find ("http" ) :]
268+         return  raw_url .strip ()
269+ 
270+     @BasePage .context_chrome  
271+     def  confirm_history_clear (self ):
272+         """ 
273+         Confirm that the history is empty 
274+         """ 
275+         self .open_history_menu ()
276+         self .expect_element_attribute_contains (
277+             "recent-history-content" , "value" , "(Empty)" 
278+         )
279+ 
197280    # Bookmarks section 
198281
199282    @BasePage .context_chrome  
@@ -268,39 +351,3 @@ def get_bookmark_tags(self, tags: List[str]) -> List[str]:
268351            )
269352            for  tag  in  tags 
270353        ]
271- 
272-     @BasePage .context_chrome  
273-     def  clear_recent_history (self , execute = True ) ->  BasePage :
274-         """Clears recent history. Case of execute=True may not be complete""" 
275-         self .open_panel_menu ()
276-         self .get_element ("panel-ui-history" ).click ()
277- 
278-         self .element_exists ("clear-recent-history" )
279-         self .element_visible ("clear-recent-history" )
280-         self .element_clickable ("clear-recent-history" )
281-         if  execute :
282-             self .click ("clear_recent_history" )
283- 
284-         return  self 
285- 
286-     @BasePage .context_chrome  
287-     def  confirm_history_clear (self ):
288-         """Confirm that the history is empty""" 
289-         self .open_history_menu ()
290-         self .expect_element_attribute_contains (
291-             "recent-history-content" , "value" , "(Empty)" 
292-         )
293- 
294-     @BasePage .context_chrome  
295-     def  reopen_recently_closed_tabs (self ) ->  BasePage :
296-         """Reopen all recently closed tabs""" 
297-         self .open_panel_menu ()
298-         self .click_on ("panel-ui-history" )
299- 
300-         self .click_on ("panel-ui-history-recently-closed" )
301-         if  self .sys_platform () ==  "Linux" :
302-             sleep (2 )
303- 
304-         self .click_on ("panel-ui-history-recently-closed-reopen-tabs" )
305- 
306-         return  self 
0 commit comments