Writing Test with an app that uses navigation

Hi,

I am using streamlit 1.36.0 and I am trying to write a test for our application.

at = AppTest.from_file(self.app_root)
at.run()

at = at.switch_page(page_file)
at.run()

I tried to render the page like so but it did not render it after the switch_page action. (I used -s on the testing run and put a print in the file and added a pdb breakpoint).

Is there a way to go into the initial run of the main script with a changed URL to force navigation to call a different page?

Main app is just navigation based on a pages dictionary (key string, value created by st.Page)

front_page = st.navigation(pages)
front_page.run()
2 Likes

Did you find a solution to this? I seem to experience the same issue with 1.37.1 and page navigation.

Calling AppTest.from_file on the app_root correctly renders elements, but using switch_page to one of the other page files does not seem to render any elements.

For my use case, I am interested in loading the main page to set a number of session_states, and then navigate to a sub-page - very similar to the streamit example here: Beyond the basics of app testing - Streamlit Docs . Session_state is correctly set and persists, but page elements is not rendered after calling switch_page.

I am running into this now on streamlit 1.38.0. We are trying to introduce the new navigation but all of the tests fail with very similar behavior where the new page doesn’t render after switching page.

Did you get it resolved?

I opened an issue here – AppTest does not render content for pages in apps using st.navigation · Issue #9446 · streamlit/streamlit · GitHub

go give it a thumbs up if this is causing you problems

Unfortunately no, I was not able to resolve the issue :slight_smile: I will follow your new post as well.