def test_dom_snapshot_dont_fetch_resources(driver):
    driver.get("https://applitools.github.io/demo/TestPages/SimpleTestPage")
    script = DomSnapshotScriptGeneric(driver)

    run_res = script.run(dont_fetch_resources=True)
    for _ in range(10):
        poll_res = script.poll_result()
        if poll_res.status is ProcessPageStatus.WIP:
            sleep(1)
        else:
            break

    assert run_res == ProcessPageResult(ProcessPageStatus.WIP)
    assert poll_res.status == ProcessPageStatus.SUCCESS
    assert poll_res.value["blobs"] == []
    assert poll_res.value["resourceUrls"] == [picture_url]
def test_dom_snapshot_default(driver):
    driver.get("https://applitools.github.io/demo/TestPages/SimpleTestPage")
    script = DomSnapshotScriptGeneric(driver)

    run_res = script.run()
    for _ in range(10):
        poll_res = script.poll_result()
        if poll_res.status is ProcessPageStatus.WIP:
            sleep(1)
        else:
            break

    assert run_res == ProcessPageResult(ProcessPageStatus.WIP)
    assert poll_res.status == ProcessPageStatus.SUCCESS
    assert poll_res.value["resourceUrls"] == []
    assert len(poll_res.value["blobs"][0]["value"]) == 0
    assert "compressed" not in poll_res.value["blobs"][0]
def test_dom_snapshot_serialize_chunks(driver):
    driver.get("https://applitools.github.io/demo/TestPages/SimpleTestPage")
    script = DomSnapshotScriptGeneric(driver)

    run_res = script.run(serialize_resources=True)
    for _ in range(10):
        poll_res = script.poll_result(chunk_byte_length=100)
        if poll_res.status is ProcessPageStatus.WIP:
            sleep(1)
        else:
            break

    assert run_res == ProcessPageResult(ProcessPageStatus.WIP)
    assert poll_res.status == ProcessPageStatus.SUCCESS_CHUNKED
    assert poll_res.done is False
    assert type(poll_res.value) is Text
    assert len(poll_res.value) == 100
def test_dom_snapshot_compressed_serialized(driver):
    driver.get("https://applitools.github.io/demo/TestPages/SimpleTestPage")
    script = DomSnapshotScriptGeneric(driver)

    run_res = script.run(compress_resources=True, serialize_resources=True)
    for _ in range(10):
        poll_res = script.poll_result()
        if poll_res.status is ProcessPageStatus.WIP:
            sleep(1)
        else:
            break

    assert run_res == ProcessPageResult(ProcessPageStatus.WIP)
    assert poll_res.status == ProcessPageStatus.SUCCESS
    assert poll_res.value["resourceUrls"] == []
    assert poll_res.value["blobs"][0]["compressed"] is True
    assert len(poll_res.value["blobs"][0]["value"]) == 28900
    serialized = poll_res.value["blobs"][0]["value"]
    compressed = base64.b64decode(serialized)
    pic = zlib.decompress(compressed)
    assert len(pic) == 22721