Skip to content

Commit 8b83b59

Browse files
committed
Tests for shot-scraper multi --har options
1 parent f202625 commit 8b83b59

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/test_shot_scraper.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,44 @@ def test_har(http_server, args, expect_zip):
259259
# Verify entries is a non-empty list
260260
assert isinstance(har_content["log"]["entries"], list)
261261
assert len(har_content["log"]["entries"]) > 0
262+
263+
264+
@pytest.mark.parametrize(
265+
"args,expect_zip",
266+
(
267+
(["--har"], False),
268+
(["--har-zip"], True),
269+
(["--har-file", "output.har"], False),
270+
(["--har-file", "output.har.zip"], True),
271+
),
272+
)
273+
def test_multi_har(http_server, args, expect_zip):
274+
runner = CliRunner()
275+
(http_server.base_dir / "two.html").write_text("<h1>Two</h1>")
276+
with runner.isolated_filesystem():
277+
pathlib.Path("shots.yml").write_text(
278+
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"
282+
)
283+
# Should be no files
284+
here = pathlib.Path(".")
285+
files = [str(p) for p in here.glob("*.*")]
286+
assert files == ["shots.yml"]
287+
result = runner.invoke(cli, ["multi", "shots.yml"] + args)
288+
assert result.exit_code == 0
289+
assert result.output.startswith("Screenshot of 'http://localhost")
290+
assert "Wrote to HAR file:" in result.output
291+
assert (".har.zip" in result.output) == expect_zip
292+
# HAR file should have been created
293+
if expect_zip:
294+
files = here.glob("*.har.zip")
295+
else:
296+
files = here.glob("*.har")
297+
har_files = list(files)
298+
# Should have created exactly one .har file
299+
assert len(har_files) == 1
300+
assert bool(zipfile.is_zipfile(har_files[0])) == expect_zip
301+
# Should have taken shots
302+
assert len(list(here.glob("*.png"))) == 2

0 commit comments

Comments
 (0)