def test_save_load_copy(tmpdir):
    driver = MockWebDriver("crop.png")
    result = Screenshot.capture_viewport("testing", driver)
    result.save(tmpdir, "mytest")
    result2 = Screenshot.load("testing", tmpdir / "testing_mytest.png")

    assert equal_images(result.image, result2.image)

    result3 = result.copy("testing3")

    assert result3.name == "testing3"
    assert equal_images(result.image, result3.image)
def test_capture_viewport():
    driver = MockWebDriver("crop.png")
    result = Screenshot.capture_viewport("testing", driver)
    reference = Image.open(ORIGINAL_DIR / "crop.png")

    assert result.name == "testing"
    assert equal_images(result.image, reference)

    result_scaled = Screenshot.capture_viewport("testing", driver, scale=3.0)
    reference_scaled = Image.open(ORIGINAL_DIR / "crop_3.png")

    assert result_scaled.name == "testing"
    assert equal_images(result_scaled.image, reference_scaled)
def test_capture(mocker):
    driver = MockWebDriver("cat.png")

    mocker.patch("webtraversallibrary.javascript.JavascriptWrapper.get_full_height", return_value=2048)
    mocker.patch(
        "webtraversallibrary.javascript.JavascriptWrapper.find_viewport",
        return_value=wtl.Rectangle(wtl.Point(0, 0), wtl.Point(256, 256)),
    )
    mocker.patch("webtraversallibrary.javascript.JavascriptWrapper.hide_position_fixed_elements", return_value={})

    result = Screenshot.capture("testing", driver, max_page_height=900)
    reference = Image.open(ORIGINAL_DIR / "page.png")

    assert result.name == "testing"
    assert equal_images(result.image, reference)