Commit 054e9ded authored by Romain Casati's avatar Romain Casati

p5 tested.

parent c7022ea6
<div style="width: 100%; text-align: center;"><canvas id="defaultCanvas0" class="p5Canvas" data-hidden="true" width="200" height="200" style="visibility: visible; width: 200px; height: 200px;"></canvas></div>
\ No newline at end of file
<div style="width: 100%; text-align: center;"><canvas id="defaultCanvas0" class="p5Canvas" data-hidden="true" style="visibility: visible; width: 200px; height: 200px;" width="200" height="200"></canvas></div>
\ No newline at end of file
from pathlib import Path
import re
import base64
import time
_test_data = Path(__file__).parent / "data"
......@@ -86,4 +87,39 @@ def test_IPython(selenium):
def test_p5(selenium):
pass
selenium.run_basthon("""
from p5 import *
x = 100
y = 100
def setup():
createCanvas(200, 200)
def draw():
background(0)
fill(255)
rect(x, y, 50, 50)
run()
""", return_data=False)
basename = f"p5_{selenium.driver.capabilities['browserName']}"
# can't access content like this
# elem = result['content']
# because of selenium's StaleElementReferenceException
# bypassing it via JS
html = selenium.run_js("return window._basthon_eval_data.display.content.outerHTML")
with open(_test_data / f"{basename}.html") as f:
target = f.read()
assert html == target
selenium.run_js("document.body.appendChild(window._basthon_eval_data.display.content);")
# this should be replaced with a clean selenium wait
time.sleep(1)
png = selenium.run_js("""
const elem = window._basthon_eval_data.display.content;
return elem.getElementsByTagName('canvas')[0].toDataURL('image/png');
""")
png = base64.b64decode(png[len('data:image/png;base64,'):])
with open(_test_data / f"{basename}.png", 'rb') as f:
target = f.read()
assert png == target
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment