I have an app with the following element:
event = st.dataframe(data=selection, on_select=“rerun”, selection_mode=‘single-row’, hide_index=True, height=‘stretch’)
I also have code that only runs if a selection is made in the table:
if len(event.selection[‘rows’])>0:
...
Using AppTest, is it possible to do something like the following to select a row?
from streamlit.testing.v1 import AppTest
app = AppTest.from_file(filename)
app.run()
row=1
app.app.dataframe[0].select(row) # Is there some mechanism like this to select a row?
AppTest doesn’t currently let you “click” rows in st.dataframe directly — there’s no .select(row) API. Row selection is handled entirely on the frontend, so the testing framework can’t simulate that interaction.
If your goal is to test the logic that runs after a row is selected, you can mock the selection state instead. For example:
app.run(inputs={“event”: {“selection”: {“rows”: [1]}}})
This runs your app as if row 1 was selected, so you can verify that your downstream code behaves correctly. In short: AppTest can validate the logic, but not the UI click itself.
I’m not sure that I understand. app.run(inputs={“event”: {“selection”: {“rows”: [1]}}}) just gets me a TypeError saying inputs is not a valid input.
> app.run(inputs={‘event’: {‘selection’: {‘rows’: [1]}}})
E TypeError: AppTest.run() got an unexpected keyword argument ‘inputs’
app.dataframe[0] also appears to not have an event or event.selection property that I can set to mock up the selection state.