Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
python-visualization
GitHub Repository: python-visualization/folium
Path: blob/main/tests/selenium/test_geojson_selenium.py
1601 views
1
from selenium.webdriver.common.by import By
2
3
import folium
4
import folium.plugins
5
from folium.utilities import temp_html_filepath
6
7
8
def test_geojson(driver):
9
"""Verify that loading data in GeoJson works well for different use cases.
10
11
Prevent two regressions:
12
- https://github.com/python-visualization/folium/pull/1190
13
- https://github.com/python-visualization/folium/pull/1289
14
15
"""
16
data_url = "https://cdn.jsdelivr.net/gh/python-visualization/folium@main/examples/data/search_bars_rome.json"
17
18
m = folium.Map((41.9, 12.5), zoom_start=10, tiles="cartodbpositron")
19
marker_cluster = folium.plugins.MarkerCluster(name="cluster").add_to(m)
20
folium.GeoJson(data_url, embed=False).add_to(marker_cluster)
21
folium.GeoJson(data_url, embed=False, show=False, name="geojson").add_to(m)
22
folium.LayerControl(collapsed=False).add_to(m)
23
24
html = m.get_root().render()
25
with temp_html_filepath(html) as filepath:
26
driver.get_file(filepath)
27
assert driver.wait_until(".folium-map")
28
driver.verify_js_logs()
29
# Verify the marker cluster is shown, it's a yellow icon with '18' in it.
30
icon = driver.wait_until(".leaflet-marker-icon.marker-cluster > div > span")
31
assert icon.text == "18"
32
# Verify the second GeoJson layer is not shown, because we used show=False.
33
control_label = driver.wait_until(
34
".leaflet-control-layers-overlays > label:nth-of-type(2)"
35
)
36
assert control_label.text == "geojson"
37
control_input = control_label.find_element(By.CSS_SELECTOR, value="input")
38
assert control_input.get_attribute("checked") is None
39
40