11from __future__ import annotations
22
3+ from typing import TYPE_CHECKING
4+
35import pytest
46
57from crawlee .browsers import BrowserPool , PlaywrightBrowserPlugin
68
9+ if TYPE_CHECKING :
10+ from httpx import URL
11+
712
8- async def test_default_plugin_new_page_creation (httpbin : str ) -> None :
13+ async def test_default_plugin_new_page_creation (httpbin : URL ) -> None :
914 async with BrowserPool () as browser_pool :
1015 page_1 = await browser_pool .new_page ()
11- await page_1 .page .goto (f' { httpbin } /get' )
16+ await page_1 .page .goto (str ( httpbin . copy_with ( path = ' /get')) )
1217 assert page_1 .browser_type == 'chromium'
13- assert page_1 .page .url == f' { httpbin } /get'
18+ assert page_1 .page .url == str ( httpbin . copy_with ( path = ' /get'))
1419 assert '<html' in await page_1 .page .content () # there is some HTML content
1520 assert browser_pool .total_pages_count == 1
1621
1722 page_2 = await browser_pool .new_page ()
18- await page_2 .page .goto (f' { httpbin } /status/200' )
23+ await page_2 .page .goto (str ( httpbin . copy_with ( path = ' /status/200')) )
1924 assert page_2 .browser_type == 'chromium'
20- assert page_2 .page .url == f' { httpbin } /status/200'
25+ assert page_2 .page .url == str ( httpbin . copy_with ( path = ' /status/200'))
2126 assert '<html' in await page_1 .page .content () # there is some HTML content
2227 assert browser_pool .total_pages_count == 2
2328
2429 await page_1 .page .close ()
2530 await page_2 .page .close ()
2631
2732
28- async def test_multiple_plugins_new_page_creation (httpbin : str ) -> None :
33+ async def test_multiple_plugins_new_page_creation (httpbin : URL ) -> None :
2934 plugin_chromium = PlaywrightBrowserPlugin (browser_type = 'chromium' )
3035 plugin_firefox = PlaywrightBrowserPlugin (browser_type = 'firefox' )
3136
3237 async with BrowserPool ([plugin_chromium , plugin_firefox ]) as browser_pool :
3338 assert browser_pool .plugins == [plugin_chromium , plugin_firefox ]
3439
3540 page_1 = await browser_pool .new_page ()
36- await page_1 .page .goto (f' { httpbin } /get' )
41+ await page_1 .page .goto (str ( httpbin . copy_with ( path = ' /get')) )
3742 assert page_1 .browser_type == 'chromium'
38- assert page_1 .page .url == f' { httpbin } /get'
43+ assert page_1 .page .url == str ( httpbin . copy_with ( path = ' /get'))
3944 assert '<html' in await page_1 .page .content () # there is some HTML content
4045
4146 page_2 = await browser_pool .new_page ()
42- await page_2 .page .goto (f' { httpbin } /headers' )
47+ await page_2 .page .goto (str ( httpbin . copy_with ( path = ' /headers')) )
4348 assert page_2 .browser_type == 'firefox'
44- assert page_2 .page .url == f' { httpbin } /headers'
49+ assert page_2 .page .url == str ( httpbin . copy_with ( path = ' /headers'))
4550 assert '<html' in await page_2 .page .content () # there is some HTML content
4651
4752 page_3 = await browser_pool .new_page ()
48- await page_3 .page .goto (f' { httpbin } /user-agent' )
53+ await page_3 .page .goto (str ( httpbin . copy_with ( path = ' /user-agent')) )
4954 assert page_3 .browser_type == 'chromium'
50- assert page_3 .page .url == f' { httpbin } /user-agent'
55+ assert page_3 .page .url == str ( httpbin . copy_with ( path = ' /user-agent'))
5156 assert '<html' in await page_3 .page .content () # there is some HTML content
5257
5358 await page_1 .page .close ()
@@ -57,7 +62,7 @@ async def test_multiple_plugins_new_page_creation(httpbin: str) -> None:
5762 assert browser_pool .total_pages_count == 3
5863
5964
60- async def test_new_page_with_each_plugin (httpbin : str ) -> None :
65+ async def test_new_page_with_each_plugin (httpbin : URL ) -> None :
6166 plugin_chromium = PlaywrightBrowserPlugin (browser_type = 'chromium' )
6267 plugin_firefox = PlaywrightBrowserPlugin (browser_type = 'firefox' )
6368
@@ -69,12 +74,12 @@ async def test_new_page_with_each_plugin(httpbin: str) -> None:
6974 assert pages [0 ].browser_type == 'chromium'
7075 assert pages [1 ].browser_type == 'firefox'
7176
72- await pages [0 ].page .goto (f' { httpbin } /get' )
73- assert pages [0 ].page .url == f' { httpbin } /get'
77+ await pages [0 ].page .goto (str ( httpbin . copy_with ( path = ' /get')) )
78+ assert pages [0 ].page .url == str ( httpbin . copy_with ( path = ' /get'))
7479 assert '<html' in await pages [0 ].page .content () # there is some HTML content
7580
76- await pages [1 ].page .goto (f' { httpbin } /headers' )
77- assert pages [1 ].page .url == f' { httpbin } /headers'
81+ await pages [1 ].page .goto (str ( httpbin . copy_with ( path = ' /headers')) )
82+ assert pages [1 ].page .url == str ( httpbin . copy_with ( path = ' /headers'))
7883 assert '<html' in await pages [1 ].page .content ()
7984
8085 for page in pages :
@@ -83,16 +88,16 @@ async def test_new_page_with_each_plugin(httpbin: str) -> None:
8388 assert browser_pool .total_pages_count == 2
8489
8590
86- async def test_with_default_plugin_constructor (httpbin : str ) -> None :
91+ async def test_with_default_plugin_constructor (httpbin : URL ) -> None :
8792 async with BrowserPool .with_default_plugin (headless = True , browser_type = 'firefox' ) as browser_pool :
8893 assert len (browser_pool .plugins ) == 1
8994 assert isinstance (browser_pool .plugins [0 ], PlaywrightBrowserPlugin )
9095
9196 page = await browser_pool .new_page ()
9297 assert page .browser_type == 'firefox'
9398
94- await page .page .goto (f' { httpbin } /get' )
95- assert page .page .url == f' { httpbin } /get'
99+ await page .page .goto (str ( httpbin . copy_with ( path = ' /get')) )
100+ assert page .page .url == str ( httpbin . copy_with ( path = ' /get'))
96101 assert '<html' in await page .page .content () # there is some HTML content
97102
98103 await page .page .close ()
@@ -114,13 +119,13 @@ async def test_new_page_with_invalid_plugin() -> None:
114119 await browser_pool .new_page (browser_plugin = plugin_2 )
115120
116121
117- async def test_resource_management (httpbin : str ) -> None :
122+ async def test_resource_management (httpbin : URL ) -> None :
118123 playwright_plugin = PlaywrightBrowserPlugin (browser_type = 'chromium' )
119124
120125 async with BrowserPool ([playwright_plugin ]) as browser_pool :
121126 page = await browser_pool .new_page ()
122- await page .page .goto (f' { httpbin } /get' )
123- assert page .page .url == f' { httpbin } /get'
127+ await page .page .goto (str ( httpbin . copy_with ( path = ' /get')) )
128+ assert page .page .url == str ( httpbin . copy_with ( path = ' /get'))
124129 assert '<html' in await page .page .content () # there is some HTML content
125130 assert browser_pool .total_pages_count == 1
126131
0 commit comments