# The AppTest class

Source: https://docs.streamlit.io/develop/api-reference/app-testing/st.testing.v1.apptest

* Function signature:

   ```python
   st.testing.v1.AppTest(script_path, *, default_timeout, args=None, kwargs=None)
   ```

* Parameters:

   | name | type | default | description |
   |---|---|---|---|
   | secrets | dict[str, Any] |  | Dictionary of secrets to be used by the simulated app. Use dict-like syntax to set secret values for the simulated app. |
   | session_state | None |  | Session State for the simulated app. Supports item and attribute access plus dict-style operations from st.session_state: get, keys, items, values, to_dict, len, and iteration. |
   | query_params | dict[str, Any] |  | Dictionary of query parameters for the simulated app. Use dict-like syntax to set values before .run(). After .run(), a single occurrence is str (a one-element list collapses to str), blank values are preserved as "", and repeated keys stay list[str]. That last case differs from st.query_params, which returns only the last value. |
   | user | dict[str, Any] | is | Dictionary of user information that the simulated app reads as st.user. The default is {"email": "test@example.com"}. To test a logged-in user, set "is_logged_in" to True and add the identity claims the app reads, such as "name" and "email". Put the tokens the app reads from st.user.tokens in a "tokens" dictionary. To test a logged-out user, set "is_logged_in" to False. st.logout() leaves the dict you assigned unchanged and replaces user with a new dict. That dict applies to the rest of the run, including an internal st.rerun(), and to later .run() calls:  If user contained "is_logged_in", it becomes {"is_logged_in": False}, so those runs take the logged-out branch. Otherwise, logout leaves user empty. |
   | context | dict[str, Any] |  | Dictionary of browser information that the simulated app reads from st.context. The supported keys are:  "timezone": A timezone name, such as "Europe/Berlin". "timezone_offset": Minutes behind UTC, such as -60 for UTC+1. AppTest does not derive this from "timezone": the offset depends on the date, so a derived value would change a test's result across daylight-saving transitions. Set both when the app reads both. "locale": A language tag, such as "de-DE". "url": The URL of the app. "is_embedded": Whether the app is embedded. "theme": "light" or "dark", read as st.context.theme.type.  A missing key or a None value reads as None. Any other key or an invalid value raises AppTestError before the script runs. |

# Initialize a simulated app using AppTest

* Function signature:

   ```python
   AppTest.from_file(cls, script_path, *, default_timeout=3)
   ```

* Parameters:

   | name | type | default | description |
   |---|---|---|---|
   | script_path | str | Path |  | Path to the app's entrypoint script. An absolute path is used as given. A relative path is resolved against the Python file that calls AppTest.from_file(). |
   | default_timeout | float | time | Default time in seconds before a script run is timed out. Can be overridden for individual .run() calls. |

* Returns: AppTest

    A simulated Streamlit app for testing. The simulated app can be
executed via .run().

* Function signature:

   ```python
   AppTest.from_string(cls, script, *, default_timeout=3)
   ```

* Parameters:

   | name | type | default | description |
   |---|---|---|---|
   | script | str |  | The string contents of the script to be run. |
   | default_timeout | float | time | Default time in seconds before a script run is timed out. Can be overridden for individual .run() calls. |

* Returns: AppTest

    A simulated Streamlit app for testing. The simulated app can be
executed via .run().

* Function signature:

   ```python
   AppTest.from_function(cls, script, *, default_timeout=3, args=None, kwargs=None)
   ```

* Parameters:

   | name | type | default | description |
   |---|---|---|---|
   | script | Callable |  | A function whose body will be used as a script. Must be runnable in isolation, so it must include any necessary imports. |
   | default_timeout | float | time | Default time in seconds before a script run is timed out. Can be overridden for individual .run() calls. |
   | args | tuple |  | An optional tuple of args to pass to the script function. |
   | kwargs | dict |  | An optional dict of kwargs to pass to the script function. |

* Returns: AppTest

    A simulated Streamlit app for testing. The simulated app can be
executed via .run().

# Run an AppTest script

* Function signature:

   ```python
   AppTest.run(*, timeout=None)
   ```

* Parameters:

   | name | type | default | description |
   |---|---|---|---|
   | timeout | float or None | timeout | The maximum number of seconds to run the script. If timeout is None (default), Streamlit uses the default timeout set for the instance of AppTest. |

* Returns: AppTest

    self

* Function signature:

   ```python
   AppTest.switch_page(page_path)
   ```

* Parameters:

   | name | type | default | description |
   |---|---|---|---|
   | page_path | str |  | Path of the page to switch to. The path must be relative to the main script's location (e.g. "pages/my_page.py"). |

* Returns: AppTest

    self

# Get AppTest script elements

The main value of `AppTest` is providing an API to programmatically inspect and interact with the elements and widgets produced by a running Streamlit app. Using the `AppTest.<element type>` properties or `AppTest.get()` method returns a collection of all the elements or widgets of the specified type that would have been displayed by running the app.

Note that you can also retrieve elements within a specific container in the same way - first retrieve the container, then retrieve the elements just in that container.

* Function signature:

   ```python
   AppTest.get(element_type)
   ```

* Parameters:

   | name | type | default | description |
   |---|---|---|---|
   | element_type | str |  | An AppTest collection name such as "button", "datetime_input", "pills", "form", or "tabs". Internal node type names such as "date_time_input" and "help_info" also work. "form_submit_button" selects submit buttons inside forms. "data_editor" selects dataframes that are not read-only. |

* Returns: Sequence of Elements

    Sequence of matching nodes, accessed by index. For example,
at.get("text")[0] for the first st.text element. Widgets
with a key are looked up on the typed collection
(at.slider(key="my_key")) or with get_by_key.

* Function signature:

   ```python
   AppTest.get_by_key(key)
   ```

* Parameters:

   | name | type | default | description |
   |---|---|---|---|
   | key | str |  | The user-provided key of the element or container. |

* Returns: Element or Block

    The matching node.

* Function signature:

   ```python
   AppTest.audio_input
   ```

* Returns: WidgetList of AudioInput

    Sequence of all st.audio_input widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.audio_input[0] for the first widget or
at.audio_input(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.button
   ```

* Returns: WidgetList of Button

    Sequence of all st.button and st.form_submit_button
widgets. Individual widgets can be accessed from a WidgetList by
index (order on the page) or key. For example, at.button[0] for
the first widget or at.button(key="my_key") for a widget with a
given key.

* Function signature:

   ```python
   AppTest.button_group
   ```

* Returns: WidgetList of ButtonGroup

    Sequence of all st.pills and st.segmented_control widgets.
Individual widgets can be accessed from a WidgetList by index
(order on the page) or key. For example, at.button_group[0] for
the first widget or at.button_group(key="my_key") for a widget
with a given key.

* Function signature:

   ```python
   AppTest.camera_input
   ```

* Returns: WidgetList of CameraInput

    Sequence of all st.camera_input widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.camera_input[0] for the first widget or
at.camera_input(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.caption
   ```

* Returns: ElementList of Caption

    Sequence of all st.caption elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.caption[0] for the first element. Caption is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.chat_input
   ```

* Returns: WidgetList of ChatInput

    Sequence of all st.chat_input widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.chat_input[0] for the first widget or
at.chat_input(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.chat_message
   ```

* Returns: BlockList of ChatMessage

    Individual messages can be accessed by index. For example,
at.chat_message[0]. st.chat_message has no key.
ChatMessage is an extension of the Block class.

* Function signature:

   ```python
   AppTest.checkbox
   ```

* Returns: WidgetList of Checkbox

    Sequence of all st.checkbox widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.checkbox[0] for the first widget or
at.checkbox(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.code
   ```

* Returns: ElementList of Code

    Sequence of all st.code elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.code[0] for the first element. Code is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.color_picker
   ```

* Returns: WidgetList of ColorPicker

    Sequence of all st.color_picker widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.color_picker[0] for the first widget or
at.color_picker(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.columns
   ```

* Returns: BlockList of Column

    Individual columns can be accessed by index. For example,
at.columns[0]. st.columns has no key. Column is an
extension of the Block class.

* Function signature:

   ```python
   AppTest.container
   ```

* Returns: BlockList

    Individual blocks can be accessed by index or key. For example,
at.container[0] or at.container(key="filters").

* Function signature:

   ```python
   AppTest.data_editor
   ```

* Returns: ElementList of Dataframe

    Sequence of all st.data_editor elements. Individual elements
can be accessed from an ElementList by index (order on the page)
or key. For example, at.data_editor[0] for the first element
or at.data_editor(key="editor") for an element with a given
key.

* Function signature:

   ```python
   AppTest.dataframe
   ```

* Returns: ElementList of Dataframe

    Sequence of all st.dataframe and st.data_editor elements.
Individual elements can be accessed from an ElementList by index
(order on the page) or, when the element has a key, by key. For
example, at.dataframe[0] for the first element or
at.dataframe(key="editor") for an element with a given key.
Dataframe is an extension of the Element class.

* Function signature:

   ```python
   AppTest.date_input
   ```

* Returns: WidgetList of DateInput

    Sequence of all st.date_input widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.date_input[0] for the first widget or
at.date_input(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.datetime_input
   ```

* Returns: WidgetList of DateTimeInput

    Sequence of all st.datetime_input widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.datetime_input[0] for the first widget or
at.datetime_input(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.divider
   ```

* Returns: ElementList of Divider

    Sequence of all st.divider elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.divider[0] for the first element. Divider is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.download_button
   ```

* Returns: WidgetList of DownloadButton

    Sequence of all st.download_button widgets. Individual widgets
can be accessed from a WidgetList by index (order on the page) or
key. For example, at.download_button[0] for the first widget or
at.download_button(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.error
   ```

* Returns: ElementList of Error

    Sequence of all st.error elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.error[0] for the first element. Error is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.exception
   ```

* Returns: ElementList of Exception

    Sequence of all st.exception elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.exception[0] for the first element. Exception is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.expander
   ```

* Returns: BlockList of Expander

    Individual expanders can be accessed by index or key. For example,
at.expander[0] or at.expander(key="details"). Expander is
an extension of the Block class.

* Function signature:

   ```python
   AppTest.feedback
   ```

* Returns: WidgetList of Feedback

    Sequence of all st.feedback widgets. Individual widgets can be
accessed from a WidgetList by index (order on the page) or key. For
example, at.feedback[0] for the first widget or
at.feedback(key="my_key") to access by key.

* Function signature:

   ```python
   AppTest.file_uploader
   ```

* Returns: WidgetList of FileUploader

    Sequence of all st.file_uploader widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.file_uploader[0] for the first widget or
at.file_uploader(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.form
   ```

* Returns: BlockList

    Individual forms can be accessed by index or by the form's
key (the form ID). For example, at.form[0] or
at.form(key="name-form").

* Function signature:

   ```python
   AppTest.form_submit_button
   ```

* Returns: WidgetList of Button

    Sequence of all st.form_submit_button widgets. Individual
widgets can be accessed from a WidgetList by index (order on the
page) or key. For example, at.form_submit_button[0] for the
first widget or at.form_submit_button(key="save") for a
widget with a given key.

* Function signature:

   ```python
   AppTest.grid
   ```

* Returns: BlockList of Grid

    Individual grids can be accessed by index or key. For example,
at.grid[0] or at.grid(key="cards"). column_count,
min_column_width, wrap, gap, vertical_alignment,
border, row_height, width, height, and dense
are available on each grid. columns stays the nested
st.columns collection. grid.cell() is not included.

* Function signature:

   ```python
   AppTest.header
   ```

* Returns: ElementList of Header

    Sequence of all st.header elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.header[0] for the first element. Header is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.help
   ```

* Returns: ElementList of Help

    Sequence of all st.help elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.help[0] for the first element. Help is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.html
   ```

* Returns: ElementList of Html

    Sequence of all st.html elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.html[0] for the first element. Html is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.image
   ```

* Returns: ElementList of Image

    Sequence of all st.image elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.image[0] for the first element. Image is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.info
   ```

* Returns: ElementList of Info

    Sequence of all st.info elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.info[0] for the first element. Info is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.json
   ```

* Returns: ElementList of Json

    Sequence of all st.json elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.json[0] for the first element. Json is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.latex
   ```

* Returns: ElementList of Latex

    Sequence of all st.latex elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.latex[0] for the first element. Latex is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.link_button
   ```

* Returns: ElementList of LinkButton

    Sequence of all st.link_button elements. Individual elements
can be accessed from an ElementList by index (order on the page)
or key. For example, at.link_button[0] for the first element
or at.link_button(key="docs") for an element with a given key.
LinkButton is an extension of the Element class.

* Function signature:

   ```python
   AppTest.main
   ```

* Returns: Block

    A container of elements. Block can be queried for elements in the
same manner as AppTest. For example, Block.checkbox will
return all st.checkbox within the associated container.

* Function signature:

   ```python
   AppTest.markdown
   ```

* Returns: ElementList of Markdown

    Sequence of all st.markdown elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.markdown[0] for the first element. Markdown is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.menu_button
   ```

* Returns: WidgetList of MenuButton

    Sequence of all st.menu_button widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.menu_button[0] for the first widget or
at.menu_button(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.metric
   ```

* Returns: ElementList of Metric

    Sequence of all st.metric elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.metric[0] for the first element. Metric is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.multiselect
   ```

* Returns: WidgetList of Multiselect

    Sequence of all st.multiselect widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.multiselect[0] for the first widget or
at.multiselect(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.number_input
   ```

* Returns: WidgetList of NumberInput

    Sequence of all st.number_input widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.number_input[0] for the first widget or
at.number_input(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.page_link
   ```

* Returns: ElementList of PageLink

    Sequence of all st.page_link elements. Individual elements can
be accessed from an ElementList by index (order on the page). For
example, at.page_link[0] for the first element. PageLink is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.pagination
   ```

* Returns: WidgetList of Pagination

    Sequence of all st.pagination widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.pagination[0] for the first widget or
at.pagination(key="my_key") for a widget with a given key.
set_value and select choose a page (1-indexed).

* Function signature:

   ```python
   AppTest.pills
   ```

* Returns: WidgetList of ButtonGroup

    Sequence of all st.pills widgets (filtered by style).
Individual widgets can be accessed from a WidgetList by index
(order on the page) or key. For example, at.pills[0] for
the first widget or at.pills(key="my_key") for a widget
with a given key.

* Function signature:

   ```python
   AppTest.progress
   ```

* Returns: ElementList of Progress

    Sequence of all st.progress elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.progress[0] for the first element. Progress is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.radio
   ```

* Returns: WidgetList of Radio

    Sequence of all st.radio widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.radio[0] for the first widget or
at.radio(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.segmented_control
   ```

* Returns: WidgetList of ButtonGroup

    Sequence of all st.segmented_control widgets (filtered by style).
Individual widgets can be accessed from a WidgetList by index
(order on the page) or key. For example, at.segmented_control[0]
for the first widget or at.segmented_control(key="my_key")
for a widget with a given key.

* Function signature:

   ```python
   AppTest.select_slider
   ```

* Returns: WidgetList of SelectSlider

    Sequence of all st.select_slider widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.select_slider[0] for the first widget or
at.select_slider(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.selectbox
   ```

* Returns: WidgetList of Selectbox

    Sequence of all st.selectbox widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.selectbox[0] for the first widget or
at.selectbox(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.sidebar
   ```

* Returns: Block

    A container of elements. Block can be queried for elements in the
same manner as AppTest. For example, Block.checkbox will
return all st.checkbox within the associated container.

* Function signature:

   ```python
   AppTest.slider
   ```

* Returns: WidgetList of Slider

    Sequence of all st.slider widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.slider[0] for the first widget or
at.slider(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.space
   ```

* Returns: ElementList of Space

    Sequence of all st.space elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.space[0] for the first element. Space is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.subheader
   ```

* Returns: ElementList of Subheader

    Sequence of all st.subheader elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.subheader[0] for the first element. Subheader is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.success
   ```

* Returns: ElementList of Success

    Sequence of all st.success elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.success[0] for the first element. Success is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.status
   ```

* Returns: BlockList of Status

    Individual status containers can be accessed by index. For
example, at.status[0]. st.status has no key. Status is
an extension of the Block class.

* Function signature:

   ```python
   AppTest.table
   ```

* Returns: ElementList of Table

    Sequence of all st.table elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.table[0] for the first element. Table is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.tabs
   ```

* Returns: BlockList of Tab

    Individual tab panels can be accessed by index. For example,
at.tabs[0]. A key on st.tabs belongs to the tab
container, not each panel; look it up with get_by_key. Tab
is an extension of the Block class.

* Function signature:

   ```python
   AppTest.text
   ```

* Returns: ElementList of Text

    Sequence of all st.text elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.text[0] for the first element. Text is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.text_area
   ```

* Returns: WidgetList of TextArea

    Sequence of all st.text_area widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.text_area[0] for the first widget or
at.text_area(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.text_input
   ```

* Returns: WidgetList of TextInput

    Sequence of all st.text_input widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.text_input[0] for the first widget or
at.text_input(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.time_input
   ```

* Returns: WidgetList of TimeInput

    Sequence of all st.time_input widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.time_input[0] for the first widget or
at.time_input(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.title
   ```

* Returns: ElementList of Title

    Sequence of all st.title elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.title[0] for the first element. Title is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.toast
   ```

* Returns: ElementList of Toast

    Sequence of all st.toast elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.toast[0] for the first element. Toast is an
extension of the Element class.

* Function signature:

   ```python
   AppTest.toggle
   ```

* Returns: WidgetList of Toggle

    Sequence of all st.toggle widgets. Individual widgets can
be accessed from a WidgetList by index (order on the page) or key.
For example, at.toggle[0] for the first widget or
at.toggle(key="my_key") for a widget with a given key.

* Function signature:

   ```python
   AppTest.warning
   ```

* Returns: ElementList of Warning

    Sequence of all st.warning elements. Individual elements can be
accessed from an ElementList by index (order on the page). For
example, at.warning[0] for the first element. Warning is an
extension of the Element class.
