@@ -756,9 +756,6 @@ def on_user_prompt_closed(info):
756756 driver .browsing_context .remove_event_handler ("user_prompt_closed" , callback_id )
757757
758758
759- @pytest .mark .xfail_chrome
760- @pytest .mark .xfail_firefox
761- @pytest .mark .xfail_edge
762759def test_add_event_handler_history_updated (driver , pages ):
763760 """Test adding event handler for history_updated event."""
764761 events_received = []
@@ -769,16 +766,17 @@ def on_history_updated(info):
769766 callback_id = driver .browsing_context .add_event_handler ("history_updated" , on_history_updated )
770767 assert callback_id is not None
771768
772- # Navigate to a page and use history API to trigger the event
773769 context_id = driver .current_window_handle
774- url = pages .url ("simpleTest.html" )
775- driver .browsing_context .navigate (context = context_id , url = url , wait = ReadinessState .COMPLETE )
770+ url1 = pages .url ("simpleTest.html" )
771+ driver .browsing_context .navigate (context = context_id , url = url1 , wait = ReadinessState .COMPLETE )
776772
777773 # Use history.pushState to trigger history updated event
778- driver .execute_script ("history.pushState({}, '', '/new-path');" )
774+ driver .script .execute ("() => { history.pushState({}, '', '/new-path'); }" )
775+ WebDriverWait (driver , 5 ).until (lambda d : len (events_received ) > 0 )
779776
780- assert len (events_received ) == 1
781- assert any ("/new-path" in event .url for event in events_received )
777+ assert len (events_received ) >= 1
778+ assert "/new-path" in events_received [0 ].url
779+ assert events_received [0 ].context == context_id
782780
783781 driver .browsing_context .remove_event_handler ("history_updated" , callback_id )
784782
0 commit comments