Skip to content

Commit

Permalink
Tests for shot-scraper multi --har options
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Feb 13, 2025
1 parent f202625 commit 8b83b59
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/test_shot_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,44 @@ def test_har(http_server, args, expect_zip):
# Verify entries is a non-empty list
assert isinstance(har_content["log"]["entries"], list)
assert len(har_content["log"]["entries"]) > 0


@pytest.mark.parametrize(
"args,expect_zip",
(
(["--har"], False),
(["--har-zip"], True),
(["--har-file", "output.har"], False),
(["--har-file", "output.har.zip"], True),
),
)
def test_multi_har(http_server, args, expect_zip):
runner = CliRunner()
(http_server.base_dir / "two.html").write_text("<h1>Two</h1>")
with runner.isolated_filesystem():
pathlib.Path("shots.yml").write_text(
f"- url: {http_server.base_url}/\n"
f" output: index.png\n"
f"- url: {http_server.base_url}/two.html\n"
f" output: two.png\n"
)
# Should be no files
here = pathlib.Path(".")
files = [str(p) for p in here.glob("*.*")]
assert files == ["shots.yml"]
result = runner.invoke(cli, ["multi", "shots.yml"] + args)
assert result.exit_code == 0
assert result.output.startswith("Screenshot of 'http://localhost")
assert "Wrote to HAR file:" in result.output
assert (".har.zip" in result.output) == expect_zip
# HAR file should have been created
if expect_zip:
files = here.glob("*.har.zip")
else:
files = here.glob("*.har")
har_files = list(files)
# Should have created exactly one .har file
assert len(har_files) == 1
assert bool(zipfile.is_zipfile(har_files[0])) == expect_zip
# Should have taken shots
assert len(list(here.glob("*.png"))) == 2

0 comments on commit 8b83b59

Please sign in to comment.