Hello, I have created a minimal reproducible example of my bokeh app. All this example does is when the user double taps on the plot, it moves the span to the location of the double tap. I want to write a test to test that when the user double taps, the span actually moves to that location.
I initially used python callbacks and those were easy to test but as the application grew I had to change the callbacks to CustomJS for speed.
I am having trouble testing the customJS callbacks. When using selenium, I struggle to find the span because the HTML only shows a canvas element and I cant seem to figure out how to access it and test the location.
I have also tried p._trigger_event()
and passed the doubletap event with position but this did not seem to actually do anything. The span location did not get updated and the assert statement failed.
I’d appreciate any tips on the best way to test a CustomJS callback. I am using bokeh 3.3.4.
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager
from bokeh.plotting import figure, output_file, show
from bokeh.models import Span, CustomJS
from bokeh.events import DoubleTap
import time
span = Span(location=1, line_color="green", line_width=2, dimension="height")
# callback to move span to position of double tap
callback = CustomJS(args=dict(span=span), code="""
span.location = cb_obj.x
""")
p = figure(
x_range = (0,10),
y_range = (0,1)
)
p.add_layout(span)
p.js_on_event(DoubleTap, callback)
output_file("test_bokeh_app.html")
show(p)