30
30
from tools .local_http_server import LocalHttpServer
31
31
32
32
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'
40
36
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'
45
46
46
47
47
48
@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 ]:
49
50
"""
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.
51
52
"""
52
- server = LocalHttpServer ('127.0.0.1' )
53
+ server = LocalHttpServer (default_host = some_domain )
53
54
yield server
54
55
55
56
server .clear ()
@@ -59,9 +60,9 @@ def local_server_http_another_host() -> Generator[LocalHttpServer, None, None]:
59
60
60
61
61
62
@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 ]:
63
64
""" Returns an instance of a LocalHttpServer with bad SSL certificate. """
64
- server = LocalHttpServer (protocol = 'https' )
65
+ server = LocalHttpServer (default_host = ssl_domain , protocol = 'https' )
65
66
yield server
66
67
67
68
server .clear ()
@@ -116,22 +117,28 @@ async def capabilities(request):
116
117
async def websocket (_websocket_connection , test_headless_mode , capabilities ,
117
118
request ):
118
119
"""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
+ }
120
129
maybe_browser_bin = os .getenv ("BROWSER_BIN" )
121
130
if maybe_browser_bin :
122
131
default_capabilities ["goog:chromeOptions" ][
123
132
"binary" ] = maybe_browser_bin
124
133
125
134
if test_headless_mode != "false" :
126
135
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" ])
130
138
else :
131
139
# 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" ])
135
142
136
143
session_capabilities = merge_dicts_recursively (default_capabilities ,
137
144
capabilities )
@@ -267,60 +274,60 @@ def url_all_origins(request, url_example, url_example_another_origin, html):
267
274
268
275
269
276
@pytest .fixture
270
- def url_base (local_server_http ):
277
+ def url_base (local_http_server ):
271
278
"""Return a generic example URL with status code 200."""
272
- return local_server_http .url_base ()
279
+ return local_http_server .url_base ()
273
280
274
281
275
282
@pytest .fixture
276
- def url_example (local_server_http ):
283
+ def url_example (local_http_server ):
277
284
"""Return a generic example URL with status code 200."""
278
- return local_server_http .url_200 ()
285
+ return local_http_server .url_200 ()
279
286
280
287
281
288
@pytest .fixture
282
- def url_example_another_origin (local_server_http_another_host ):
289
+ def url_example_another_origin (local_http_server , another_domain ):
283
290
"""Return a generic example URL with status code 200, in a domain other than
284
291
the example_url fixture."""
285
- return local_server_http_another_host .url_200 ()
292
+ return local_http_server .url_200 (host = another_domain )
286
293
287
294
288
295
@pytest .fixture
289
- def url_auth_required (local_server_http ):
296
+ def url_auth_required (local_http_server ):
290
297
"""Return a URL that requires authentication (status code 401).
291
298
Alternatively, any of the following URLs could also be used:
292
299
- "https://authenticationtest.com/HTTPAuth/"
293
300
- "http://the-internet.herokuapp.com/basic_auth"
294
301
- "http://httpstat.us/401"
295
302
"""
296
- return local_server_http .url_basic_auth ()
303
+ return local_http_server .url_basic_auth ()
297
304
298
305
299
306
@pytest .fixture
300
- def url_hang_forever (local_server_http ):
307
+ def url_hang_forever (local_http_server ):
301
308
"""Return a URL that hangs forever."""
302
309
try :
303
- yield local_server_http .url_hang_forever ()
310
+ yield local_http_server .url_hang_forever ()
304
311
finally :
305
- local_server_http .hang_forever_stop ()
312
+ local_http_server .hang_forever_stop ()
306
313
307
314
308
315
@pytest .fixture (scope = "session" )
309
- def url_bad_ssl (local_server_bad_ssl ):
316
+ def url_bad_ssl (local_server_bad_ssl , ssl_domain ):
310
317
"""
311
318
Return a URL with an invalid certificate authority from a SSL certificate.
312
319
In Chromium, this generates the following error:
313
320
314
321
> Your connection is not private
315
322
> NET::ERR_CERT_AUTHORITY_INVALID
316
323
"""
317
- return local_server_bad_ssl .url_200 ()
324
+ return local_server_bad_ssl .url_200 (host = ssl_domain )
318
325
319
326
320
327
@pytest .fixture
321
- def url_cacheable (local_server_http ):
328
+ def url_cacheable (local_http_server ):
322
329
"""Return a generic example URL that can be cached."""
323
- return local_server_http .url_cacheable ()
330
+ return local_http_server .url_cacheable ()
324
331
325
332
326
333
@pytest .fixture
@@ -509,11 +516,11 @@ async def activate_main_tab():
509
516
510
517
511
518
@pytest .fixture
512
- def url_download (local_server_http ):
519
+ def url_download (local_http_server ):
513
520
"""Return a URL that triggers a download."""
514
521
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 ,
517
524
content_type = "text/html" ,
518
525
headers = {
519
526
"Content-Disposition" : f"attachment; filename=\" { file_name } \" "
@@ -523,13 +530,14 @@ def url_download(file_name="file-name.txt", content="download content"):
523
530
524
531
525
532
@pytest .fixture
526
- def html (local_server_http , local_server_http_another_host ):
533
+ def html (local_http_server , some_domain , another_domain ):
527
534
"""Return a factory for URL with the given content."""
528
535
def html (content = "" , same_origin = True ):
529
536
if same_origin :
530
- return local_server_http .url_200 (content = content )
537
+ return local_http_server .url_200 (host = some_domain , content = content )
531
538
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 )
533
541
534
542
return html
535
543
0 commit comments