3030from tools .local_http_server import LocalHttpServer
3131
3232
33- @pytest_asyncio .fixture (scope = 'session' )
34- def local_server_http () -> Generator [LocalHttpServer , None , None ]:
35- """
36- Returns an instance of a LocalHttpServer without SSL pointing to localhost.
37- """
38- server = LocalHttpServer ()
39- yield server
33+ @pytest .fixture (scope = "session" )
34+ def some_domain ():
35+ return 'some_domain.test'
4036
41- server .clear ()
42- if server .is_running ():
43- server .stop ()
44- return
37+
38+ @pytest .fixture (scope = "session" )
39+ def another_domain ():
40+ return 'another_domain.test'
41+
42+
43+ @pytest .fixture (scope = "session" )
44+ def ssl_domain ():
45+ return 'ssl_domain.test'
4546
4647
4748@pytest_asyncio .fixture (scope = 'session' )
48- def local_server_http_another_host ( ) -> Generator [LocalHttpServer , None , None ]:
49+ def local_http_server ( some_domain ) -> Generator [LocalHttpServer , None , None ]:
4950 """
50- Returns an instance of a LocalHttpServer without SSL pointing to `127.0.0.1`
51+ Returns an instance of a LocalHttpServer without SSL pointing to localhost.
5152 """
52- server = LocalHttpServer ('127.0.0.1' )
53+ server = LocalHttpServer (default_host = some_domain )
5354 yield server
5455
5556 server .clear ()
@@ -59,9 +60,9 @@ def local_server_http_another_host() -> Generator[LocalHttpServer, None, None]:
5960
6061
6162@pytest_asyncio .fixture (scope = 'session' )
62- def local_server_bad_ssl () -> Generator [LocalHttpServer , None , None ]:
63+ def local_server_bad_ssl (ssl_domain ) -> Generator [LocalHttpServer , None , None ]:
6364 """ Returns an instance of a LocalHttpServer with bad SSL certificate. """
64- server = LocalHttpServer (protocol = 'https' )
65+ server = LocalHttpServer (default_host = ssl_domain , protocol = 'https' )
6566 yield server
6667
6768 server .clear ()
@@ -116,22 +117,28 @@ async def capabilities(request):
116117async def websocket (_websocket_connection , test_headless_mode , capabilities ,
117118 request ):
118119 """Return a websocket with an active BiDi session."""
119- default_capabilities = {"webSocketUrl" : True , "goog:chromeOptions" : {}}
120+ default_capabilities = {
121+ "webSocketUrl" : True ,
122+ "goog:chromeOptions" : {
123+ "args" : [
124+ # Required for testing with `.test` domains.
125+ '--host-resolver-rules=MAP *.test 127.0.0.1' ,
126+ ]
127+ }
128+ }
120129 maybe_browser_bin = os .getenv ("BROWSER_BIN" )
121130 if maybe_browser_bin :
122131 default_capabilities ["goog:chromeOptions" ][
123132 "binary" ] = maybe_browser_bin
124133
125134 if test_headless_mode != "false" :
126135 if test_headless_mode == "old" :
127- default_capabilities ["goog:chromeOptions" ]["args" ] = [
128- "--headless=old" , '--hide-scrollbars' , '--mute-audio'
129- ]
136+ default_capabilities ["goog:chromeOptions" ]["args" ].extend (
137+ ["--headless=old" , "--hide-scrollbars" , "--mute-audio" ])
130138 else :
131139 # Default to new headless mode.
132- default_capabilities ["goog:chromeOptions" ]["args" ] = [
133- "--headless=new"
134- ]
140+ default_capabilities ["goog:chromeOptions" ]["args" ].extend (
141+ ["--headless=new" ])
135142
136143 session_capabilities = merge_dicts_recursively (default_capabilities ,
137144 capabilities )
@@ -267,60 +274,60 @@ def url_all_origins(request, url_example, url_example_another_origin, html):
267274
268275
269276@pytest .fixture
270- def url_base (local_server_http ):
277+ def url_base (local_http_server ):
271278 """Return a generic example URL with status code 200."""
272- return local_server_http .url_base ()
279+ return local_http_server .url_base ()
273280
274281
275282@pytest .fixture
276- def url_example (local_server_http ):
283+ def url_example (local_http_server ):
277284 """Return a generic example URL with status code 200."""
278- return local_server_http .url_200 ()
285+ return local_http_server .url_200 ()
279286
280287
281288@pytest .fixture
282- def url_example_another_origin (local_server_http_another_host ):
289+ def url_example_another_origin (local_http_server , another_domain ):
283290 """Return a generic example URL with status code 200, in a domain other than
284291 the example_url fixture."""
285- return local_server_http_another_host .url_200 ()
292+ return local_http_server .url_200 (host = another_domain )
286293
287294
288295@pytest .fixture
289- def url_auth_required (local_server_http ):
296+ def url_auth_required (local_http_server ):
290297 """Return a URL that requires authentication (status code 401).
291298 Alternatively, any of the following URLs could also be used:
292299 - "https://authenticationtest.com/HTTPAuth/"
293300 - "http://the-internet.herokuapp.com/basic_auth"
294301 - "http://httpstat.us/401"
295302 """
296- return local_server_http .url_basic_auth ()
303+ return local_http_server .url_basic_auth ()
297304
298305
299306@pytest .fixture
300- def url_hang_forever (local_server_http ):
307+ def url_hang_forever (local_http_server ):
301308 """Return a URL that hangs forever."""
302309 try :
303- yield local_server_http .url_hang_forever ()
310+ yield local_http_server .url_hang_forever ()
304311 finally :
305- local_server_http .hang_forever_stop ()
312+ local_http_server .hang_forever_stop ()
306313
307314
308315@pytest .fixture (scope = "session" )
309- def url_bad_ssl (local_server_bad_ssl ):
316+ def url_bad_ssl (local_server_bad_ssl , ssl_domain ):
310317 """
311318 Return a URL with an invalid certificate authority from a SSL certificate.
312319 In Chromium, this generates the following error:
313320
314321 > Your connection is not private
315322 > NET::ERR_CERT_AUTHORITY_INVALID
316323 """
317- return local_server_bad_ssl .url_200 ()
324+ return local_server_bad_ssl .url_200 (host = ssl_domain )
318325
319326
320327@pytest .fixture
321- def url_cacheable (local_server_http ):
328+ def url_cacheable (local_http_server ):
322329 """Return a generic example URL that can be cached."""
323- return local_server_http .url_cacheable ()
330+ return local_http_server .url_cacheable ()
324331
325332
326333@pytest .fixture
@@ -509,11 +516,11 @@ async def activate_main_tab():
509516
510517
511518@pytest .fixture
512- def url_download (local_server_http ):
519+ def url_download (local_http_server ):
513520 """Return a URL that triggers a download."""
514521 def url_download (file_name = "file-name.txt" , content = "download content" ):
515- return local_server_http .url_200 (
516- content ,
522+ return local_http_server .url_200 (
523+ content = content ,
517524 content_type = "text/html" ,
518525 headers = {
519526 "Content-Disposition" : f"attachment; filename=\" { file_name } \" "
@@ -523,13 +530,14 @@ def url_download(file_name="file-name.txt", content="download content"):
523530
524531
525532@pytest .fixture
526- def html (local_server_http , local_server_http_another_host ):
533+ def html (local_http_server , some_domain , another_domain ):
527534 """Return a factory for URL with the given content."""
528535 def html (content = "" , same_origin = True ):
529536 if same_origin :
530- return local_server_http .url_200 (content = content )
537+ return local_http_server .url_200 (host = some_domain , content = content )
531538 else :
532- return local_server_http_another_host .url_200 (content = content )
539+ return local_http_server .url_200 (host = another_domain ,
540+ content = content )
533541
534542 return html
535543
0 commit comments