Skip to content

Commit 6343237

Browse files
committed
use a fixed figure size and crop the screenshot
1 parent 9c10eb1 commit 6343237

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

tests/selenium/test_heat_map_selenium.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ def test_heat_map_with_weights(driver):
1515
This test will fail in non-headless mode because window size will be different.
1616
1717
"""
18-
m = folium.Map((0.5, 0.5), zoom_start=8, tiles=None)
18+
figure_width, figure_height = 800, 600
19+
m = folium.Map(
20+
(0.5, 0.5),
21+
zoom_start=8,
22+
tiles=None,
23+
width=figure_width,
24+
height=figure_height,
25+
)
1926
HeatMap(
2027
# make four dots with different weights: 1, 1, 1.5 and 2.
2128
data=[
@@ -34,17 +41,14 @@ def test_heat_map_with_weights(driver):
3441
driver.verify_js_logs()
3542
canvas = driver.wait_until("canvas.leaflet-heatmap-layer")
3643
assert canvas
37-
# Print the canvas size
38-
canvas_size = driver.execute_script(
39-
"return {width: arguments[0].width, height: arguments[0].height};", canvas
40-
)
41-
print(f"Canvas size: {canvas_size['width']}x{canvas_size['height']}")
4244
# get the canvas as a PNG base64 string
4345
canvas_base64 = driver.execute_script(
4446
"return arguments[0].toDataURL('image/png').substring(21);", canvas
4547
)
4648
screenshot_bytes = base64.b64decode(canvas_base64)
4749
screenshot = Image.open(io.BytesIO(screenshot_bytes))
50+
# window size is not reliable, so crop to a smaller fixed size
51+
screenshot = screenshot.crop((0, 0, figure_width, figure_height))
4852
path = os.path.dirname(__file__)
4953
with open(os.path.join(path, "test_heat_map_selenium_screenshot.png"), "rb") as f:
5054
screenshot_expected = Image.open(f)
-24.5 KB
Loading

0 commit comments

Comments
 (0)