Skip to content

Commit 3d95b70

Browse files
committed
Add selenium test for wasm
1 parent 529da3f commit 3d95b70

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/wasm/test_demo.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import time
2+
3+
from selenium import webdriver
4+
from selenium.webdriver.chrome.options import Options
5+
import pytest
6+
7+
RUN_CODE_TEMPLATE = """
8+
var output = "";
9+
save_output = function(text) {{
10+
output += text
11+
}};
12+
var vm = window.rp.vmStore.init('test_vm');
13+
vm.setStdout(save_output);
14+
vm.exec('{}');
15+
vm.destroy();
16+
return output;
17+
"""
18+
19+
@pytest.fixture(scope="module")
20+
def driver(request):
21+
options = Options()
22+
options.headless = True
23+
options.add_argument('--disable-gpu')
24+
driver = webdriver.Chrome(options=options)
25+
driver.get("http://localhost:8080")
26+
assert "RustPython" in driver.title
27+
time.sleep(5)
28+
yield driver
29+
driver.close()
30+
31+
32+
@pytest.mark.parametrize("script, output",
33+
[
34+
("print(5)", "5"),
35+
("a=5;b=4;print(a+b)", "9")
36+
]
37+
)
38+
def test_demo(driver, script, output):
39+
script = RUN_CODE_TEMPLATE.format(script)
40+
assert driver.execute_script(script).strip() == output

0 commit comments

Comments
 (0)