Skip to content

Commit ea07a84

Browse files
committed
Add a playwright test
1 parent c41e609 commit ea07a84

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
4+
from shiny import App, Inputs, Outputs, Session, render, ui
5+
6+
app_ui = ui.page_sidebar(
7+
ui.sidebar(
8+
ui.input_slider("obs", "Number of observations:", min=0, max=1000, value=500),
9+
open="closed",
10+
),
11+
ui.h3("clientData values"),
12+
ui.output_text_verbatim("clientdatatext"),
13+
ui.output_plot("myplot"),
14+
title="Shiny Client Data",
15+
)
16+
17+
18+
def server(input: Inputs, output: Outputs, session: Session):
19+
@render.text
20+
def clientdatatext():
21+
cdata = session.clientdata
22+
return "\n".join([f"{name} = {cdata[name]()}" for name in reversed(dir(cdata))])
23+
24+
@render.plot
25+
def myplot():
26+
plt.figure()
27+
plt.hist(np.random.normal(size=input.obs()))
28+
plt.title("This is myplot")
29+
30+
31+
app = App(app_ui, server)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import re
2+
3+
from playwright.sync_api import Page
4+
5+
from shiny.playwright import controller
6+
from shiny.run import ShinyAppProc
7+
8+
9+
def test_output_image_kitchen(page: Page, local_app: ShinyAppProc) -> None:
10+
11+
page.goto(local_app.url)
12+
13+
text = controller.OutputTextVerbatim(page, "clientdatatext")
14+
15+
# This doesn't cover all the clientdata values since some of them
16+
# are environment-dependent. However, this at least checks that the
17+
# clientdata object is available and that some values are present.
18+
text.expect.to_contain_text("url_protocol = http")
19+
text.expect.to_contain_text("url_pathname = /")
20+
text.expect.to_contain_text(
21+
re.compile("url_hostname = (localhost|127\\.0\\.0\\.1)")
22+
)
23+
text.expect.to_contain_text("output_myplot_hidden = False")
24+
text.expect.to_contain_text("output_myplot_bg = rgb(255, 255, 255)")
25+
text.expect.to_contain_text("output_clientdatatext_hidden = False")

0 commit comments

Comments
 (0)