@@ -262,31 +262,36 @@ def test_har(http_server, args, expect_zip):
262262
263263
264264@pytest .mark .parametrize (
265- "args,expect_zip" ,
265+ "args,expect_zip,record_shots " ,
266266 (
267- (["--har" ], False ),
268- (["--har-zip" ], True ),
269- (["--har-file" , "output.har" ], False ),
270- (["--har-file" , "output.har.zip" ], True ),
267+ (["--har" ], False , True ),
268+ (["--har-zip" ], True , True ),
269+ (["--har-file" , "output.har" ], False , True ),
270+ (["--har-file" , "output.har.zip" ], True , True ),
271+ # And one where we don't record the shots:
272+ (["--har" ], False , False ),
271273 ),
272274)
273- def test_multi_har (http_server , args , expect_zip ):
275+ def test_multi_har (http_server , args , expect_zip , record_shots ):
274276 runner = CliRunner ()
275277 (http_server .base_dir / "two.html" ).write_text ("<h1>Two</h1>" )
276278 with runner .isolated_filesystem ():
277279 pathlib .Path ("shots.yml" ).write_text (
278280 f"- url: { http_server .base_url } /\n "
279- f" output: index.png\n "
280- f"- url: { http_server .base_url } /two.html\n "
281- f" output: two.png\n "
281+ + ( f" output: index.png\n " if record_shots else "" )
282+ + f"- url: { http_server .base_url } /two.html\n "
283+ + ( f" output: two.png\n " if record_shots else "" )
282284 )
283285 # Should be no files
284286 here = pathlib .Path ("." )
285287 files = [str (p ) for p in here .glob ("*.*" )]
286288 assert files == ["shots.yml" ]
287289 result = runner .invoke (cli , ["multi" , "shots.yml" ] + args )
288290 assert result .exit_code == 0
289- assert result .output .startswith ("Screenshot of 'http://localhost" )
291+ if record_shots :
292+ assert result .output .startswith ("Screenshot of 'http://localhost" )
293+ else :
294+ assert result .output .startswith ("Skipping screenshot of 'http://localhost" )
290295 assert "Wrote to HAR file:" in result .output
291296 assert (".har.zip" in result .output ) == expect_zip
292297 # HAR file should have been created
@@ -298,5 +303,9 @@ def test_multi_har(http_server, args, expect_zip):
298303 # Should have created exactly one .har file
299304 assert len (har_files ) == 1
300305 assert bool (zipfile .is_zipfile (har_files [0 ])) == expect_zip
301- # Should have taken shots
302- assert len (list (here .glob ("*.png" ))) == 2
306+ shot_files = list (here .glob ("*.png" ))
307+ num_shots = len (shot_files )
308+ if record_shots :
309+ assert num_shots == 2
310+ else :
311+ assert num_shots == 0
0 commit comments