Testing element classes

The Block class has the same methods and attributes as AppTest. A Block instance represents a container of elements just as AppTest represents the entire app. For example, Block.button will produce a WidgetList of Button in the same manner as AppTest.button.

ChatMessage, Column, and Tab all inherit from Block. For all container classes, parameters of the original element can be obtained as properties. For example, ChatMessage.avatar and Tab.label.

Element base class for testing.

This class's methods and attributes are universal for all elements implemented in testing. For example, Caption, Code, Text, and Title inherit from Element. All widget classes also inherit from Element, but have additional methods specific to each widget type. See the AppTest class for the full list of supported elements.

For all element classes, parameters of the original element can be obtained as properties. For example, Button.label, Caption.help, and Toast.icon.

Class description[source]

st.testing.v1.element_tree.Element(proto, root)

Methods

run(*, timeout=None)

Run the AppTest script which contains the element.

Attributes

The value or contents of the element.

A representation of st.button and st.form_submit_button.

Class description[source]

st.testing.v1.element_tree.Button(proto, root)

Methods

click()

Set the value of the button to True.

run(*, timeout=None)

Run the AppTest script which contains the element.

Set the value of the button.

Attributes

The value of the button. (bool)

A representation of st.chat_input.

Class description[source]

st.testing.v1.element_tree.ChatInput(proto, root)

Methods

run(*, timeout=None)

Run the AppTest script which contains the element.

Set the value of the widget.

Attributes

The value of the widget. (str)

A representation of st.checkbox.

Class description[source]

st.testing.v1.element_tree.Checkbox(proto, root)

Methods

check()

Set the value of the widget to True.

run(*, timeout=None)

Run the AppTest script which contains the element.

Set the value of the widget.

Set the value of the widget to False.

Attributes

The value of the widget. (bool)

A representation of st.color_picker.

Class description[source]

st.testing.v1.element_tree.ColorPicker(proto, root)

Methods

pick(v)

Set the value of the widget as a hex string. May omit the "#" prefix.

run(*, timeout=None)

Run the AppTest script which contains the element.

Set the value of the widget as a hex string.

Attributes

The currently selected value as a hex string. (str)

A representation of st.date_input.

Class description[source]

st.testing.v1.element_tree.DateInput(proto, root)

Methods

run(*, timeout=None)

Run the AppTest script which contains the element.

Set the value of the widget.

Attributes

The value of the widget. (date or Tuple of date)

A representation of st.multiselect.

Class description[source]

st.testing.v1.element_tree.Multiselect(proto, root)

Methods

run(*, timeout=None)

Run the AppTest script which contains the element.

select(v)

Add a selection to the widget. Do nothing if the value is already selected. If testing a multiselect widget with repeated options, use set_value instead.

Set the value of the multiselect widget. (list)

Remove a selection from the widget. Do nothing if the value is not already selected. If a value is selected multiple times, the first instance is removed.

Attributes

The widget's formatting function for displaying options. (callable)

The indices of the currently selected values from the options. (list)

The currently selected values from the options. (list)

A representation of st.number_input.

Class description[source]

st.testing.v1.element_tree.NumberInput(proto, root)

Methods

Decrement the st.number_input widget as if the user clicked "-".

Increment the st.number_input widget as if the user clicked "+".

run(*, timeout=None)

Run the AppTest script which contains the element.

Set the value of the st.number_input widget.

Attributes

Get the current value of the st.number_input widget.

A representation of st.radio.

Class description[source]

st.testing.v1.element_tree.Radio(proto, root)

Methods

run(*, timeout=None)

Run the AppTest script which contains the element.

Set the selection by value.

Attributes

The widget's formatting function for displaying options. (callable)

The index of the current selection. (int)

The currently selected value from the options. (Any)

A representation of st.select_slider.

Class description[source]

st.testing.v1.element_tree.SelectSlider(proto, root)

Methods

run(*, timeout=None)

Run the AppTest script which contains the element.

set_range(lower, upper)

Set the ranged selection by values.

Set the (single) selection by value.

Attributes

The widget's formatting function for displaying options. (callable)

The currently selected value or range. (Any or Sequence of Any)

A representation of st.selectbox.

Class description[source]

st.testing.v1.element_tree.Selectbox(proto, root)

Methods

run(*, timeout=None)

Run the AppTest script which contains the element.

select(v)

Set the selection by value.

select_index(index)

Set the selection by index.

Set the selection by value.

Attributes

The widget's formatting function for displaying options. (callable)

The index of the current selection. (int)

The currently selected value from the options. (Any)

A representation of st.slider.

Class description[source]

st.testing.v1.element_tree.Slider(proto, root)

Methods

run(*, timeout=None)

Run the AppTest script which contains the element.

set_range(lower, upper)

Set the ranged value of the slider.

Set the (single) value of the slider.

Attributes

The currently selected value or range. (Any or Sequence of Any)

A representation of st.text_area.

Class description[source]

st.testing.v1.element_tree.TextArea(proto, root)

Methods

input(v)

Set the value of the widget only if the value does not exceed the maximum allowed characters.

run(*, timeout=None)

Run the AppTest script which contains the element.

Set the value of the widget.

Attributes

The current value of the widget. (str)

A representation of st.text_input.

Class description[source]

st.testing.v1.element_tree.TextInput(proto, root)

Methods

input(v)

Set the value of the widget only if the value does not exceed the maximum allowed characters.

run(*, timeout=None)

Run the AppTest script which contains the element.

Set the value of the widget.

Attributes

The current value of the widget. (str)

A representation of st.time_input.

Class description[source]

st.testing.v1.element_tree.TimeInput(proto, root)

Methods

Select the previous available time.

Select the next available time.

run(*, timeout=None)

Run the AppTest script which contains the element.

Set the value of the widget.

Attributes

The current value of the widget. (time)

A representation of st.toggle.

Class description[source]

st.testing.v1.element_tree.Toggle(proto, root)

Methods

run(*, timeout=None)

Run the AppTest script which contains the element.

Set the value of the widget.

Attributes

The current value of the widget. (bool)

forum

Still have questions?

Our forums are full of helpful information and Streamlit experts.