Skip to content

Commit d89a8b3

Browse files
committed
Add a basic playwright test
1 parent df8ff12 commit d89a8b3

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import asyncio
2+
3+
from shiny import reactive
4+
from shiny.express import input, render, ui
5+
6+
stream = ui.MarkdownStream("stream_id")
7+
stream.ui()
8+
9+
10+
ui.input_action_button("do_stream", "Do stream")
11+
12+
13+
async def gen():
14+
yield "Hello "
15+
await asyncio.sleep(0.1)
16+
yield "world!"
17+
18+
19+
@reactive.effect
20+
@reactive.event(input.do_stream)
21+
async def _():
22+
await stream.stream(gen())
23+
24+
25+
@render.code
26+
def stream_result():
27+
res = stream.latest_stream.result()
28+
return f"Stream result: {res}"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from playwright.sync_api import Page, expect
2+
3+
from shiny.playwright import controller
4+
from shiny.run import ShinyAppProc
5+
6+
7+
def test_latest_stream_result(page: Page, local_app: ShinyAppProc) -> None:
8+
page.goto(local_app.url)
9+
10+
stream = page.locator("#stream_id")
11+
stream_result = controller.OutputCode(page, "stream_result")
12+
stream_result.expect_value("")
13+
14+
btn = controller.InputActionButton(page, "do_stream")
15+
btn.click()
16+
17+
expect(stream).to_contain_text("Hello world!")
18+
stream_result.expect_value("Stream result: Hello world!")

0 commit comments

Comments
 (0)