@@ -389,7 +389,6 @@ class TestTabNavigation:
389389 async def test_go_to_new_url (self , tab ):
390390 """Test navigating to a new URL."""
391391 tab ._connection_handler .execute_command .side_effect = [
392- {'result' : {'result' : {'value' : 'https://old-url.com' }}}, # current_url
393392 {'result' : {}}, # Page.enable
394393 {'result' : {'frameId' : 'frame-id' }}, # navigate command
395394 {'result' : {}}, # Page.disable
@@ -403,15 +402,37 @@ async def fire_callback(event_name, callback, temporary=False):
403402
404403 await tab .go_to ('https://example.com' )
405404
406- assert tab ._connection_handler .execute_command .call_count == 4
405+ assert tab ._connection_handler .execute_command .call_count == 3
406+
407+ @pytest .mark .asyncio
408+ async def test_go_to_navigation_error (self , tab ):
409+ """Test that navigation errors raise NavigationError."""
410+ from pydoll .exceptions import NavigationError
411+
412+ tab ._connection_handler .execute_command .side_effect = [
413+ {'result' : {}}, # Page.enable
414+ {'result' : {'frameId' : 'f' , 'errorText' : 'net::ERR_NAME_NOT_RESOLVED' }},
415+ {'result' : {}}, # Page.disable
416+ ]
417+
418+ async def fire_callback (event_name , callback , temporary = False ):
419+ callback ({'method' : event_name , 'params' : {}})
420+ return 1
421+
422+ tab ._connection_handler .register_callback = AsyncMock (
423+ side_effect = fire_callback
424+ )
425+
426+ with pytest .raises (NavigationError ) as exc_info :
427+ await tab .go_to ('https://nonexistent.invalid' )
428+ assert 'net::ERR_NAME_NOT_RESOLVED' in str (exc_info .value )
407429
408430 @pytest .mark .asyncio
409431 async def test_go_to_same_url (self , tab ):
410- """Test navigating to the same URL (should refresh) ."""
432+ """Test navigating to the same URL works the same as a new URL ."""
411433 tab ._connection_handler .execute_command .side_effect = [
412- {'result' : {'result' : {'value' : 'https://example.com' }}}, # current_url
413434 {'result' : {}}, # Page.enable
414- {'result' : {}}, # refresh command
435+ {'result' : {'frameId' : 'frame-id' }}, # navigate command
415436 {'result' : {}}, # Page.disable
416437 ]
417438
@@ -423,13 +444,12 @@ async def fire_callback(event_name, callback, temporary=False):
423444
424445 await tab .go_to ('https://example.com' )
425446
426- assert tab ._connection_handler .execute_command .call_count == 4
447+ assert tab ._connection_handler .execute_command .call_count == 3
427448
428449 @pytest .mark .asyncio
429450 async def test_go_to_timeout (self , tab ):
430451 """Test navigation timeout."""
431452 tab ._connection_handler .execute_command .side_effect = [
432- {'result' : {'result' : {'value' : 'https://old-url.com' }}}, # current_url
433453 {'result' : {}}, # Page.enable
434454 {'result' : {'frameId' : 'frame-id' }}, # navigate command
435455 {'result' : {}}, # Page.disable
@@ -1827,38 +1847,6 @@ async def fire_callback(event_name, callback, temporary=False):
18271847
18281848 assert tab ._page_events_enabled is False
18291849
1830- @pytest .mark .asyncio
1831- async def test_refresh_if_url_not_changed_same_url (self , tab ):
1832- """Test _refresh_if_url_not_changed with same URL."""
1833- tab ._connection_handler .execute_command .side_effect = [
1834- {'result' : {'result' : {'value' : 'https://example.com' }}}, # current_url call
1835- {'result' : {}}, # Page.enable
1836- {'result' : {}}, # refresh call
1837- {'result' : {}}, # Page.disable
1838- ]
1839-
1840- async def fire_callback (event_name , callback , temporary = False ):
1841- callback ({'method' : event_name , 'params' : {}})
1842- return 1
1843-
1844- tab ._connection_handler .register_callback = AsyncMock (side_effect = fire_callback )
1845-
1846- result = await tab ._refresh_if_url_not_changed ('https://example.com' )
1847-
1848- assert result is True
1849- assert tab ._connection_handler .execute_command .call_count == 4
1850-
1851- @pytest .mark .asyncio
1852- async def test_refresh_if_url_not_changed_different_url (self , tab ):
1853- """Test _refresh_if_url_not_changed with different URL."""
1854- tab ._connection_handler .execute_command .return_value = {
1855- 'result' : {'result' : {'value' : 'https://different.com' }}
1856- }
1857-
1858- result = await tab ._refresh_if_url_not_changed ('https://example.com' )
1859-
1860- assert result is False
1861- assert_mock_called_at_least_once (tab ._connection_handler )
18621850
18631851
18641852class TestTabRequestManagement :
0 commit comments