Repository: streamlit/streamlit
File: e2e_playwright/markdown_features_test.py (Python)

Code before:
        for element_name, disallowed_features in DISALLOWED_MARKDOWN_FEATURES.items():
            # Get the container for the current element
            container = get_element_by_key(app, element_name)
            expect(container).to_be_visible()

            if element_name == "st_dialog":
                # Click the button to open the dialog
                button = container.get_by_role("button", name="Open Dialog")
                button.click()

                # Set the container to the dialog so we can test the markdown
                container = app.get_by_test_id("stDialog")
                expect(container).to_be_visible()

            markdown_container_test_id = "stMarkdownContainer"

            # st.caption and st.image caption uses a different container
            if element_name in ["st_caption", "st_image"]:
                markdown_container_test_id = "stCaptionContainer"

            if element_name == "st_select_slider":
                # st.select_slider has 3 markdown containers:
                # 1. The min label
                # 2. The max label
                # 3. The current option
                slider_markdown_containers = container.locator(
                    "[data-testid='stMarkdownContainer']"
                )
                feature_locator = locator_fn(slider_markdown_containers)
                if feature in disallowed_features:
                    # Feature should not be present in any markdown container
                    expect(feature_locator.first).not_to_be_attached()
                else:
                    # Feature should be present in at least one markdown container
                    expect(feature_locator.first).to_be_visible()

                continue

            # General case for other elements
            element_locator = locator_fn(
                container.get_by_test_id(markdown_container_test_id)
            )

            if feature in disallowed_features:
                # Feature should not be present
                expect(element_locator.first).not_to_be_attached()
            else:
                # Feature should be present
                expect(element_locator.first).to_be_visible()

            if element_name == "st_dialog":

Review comment (suggestion):
instead of a special case for st_select_slider, you could also do it like its done here: https://github.com/streamlit/streamlit/pull/13094/files#diff-be57b93a92966b216b60f3b3bbf20b5b8ff767036c9ce4d9510460f36204da36

Code after:
    for feature, locator_fn in MARKDOWN_FEATURE_PLAYWRIGHT_LOCATORS.items():
        # Select the current markdown feature
        select_radio_option(app, re.compile(f"^{feature}$"), label="Markdown Features")

        # Test the feature against all Streamlit elements
        for element_name, disallowed_features in DISALLOWED_MARKDOWN_FEATURES.items():
            # Get the container for the current element
            container = get_element_by_key(app, element_name)
            expect(container).to_be_visible()

            if element_name == "st_dialog":
                # Click the button to open the dialog
                button = container.get_by_role("button", name="Open Dialog")
                button.click()

                # Set the container to the dialog so we can test the markdown
                container = app.get_by_test_id("stDialog")
                expect(container).to_be_visible()

            markdown_container_test_id = "stMarkdownContainer"

            # st.caption and st.image caption uses a different container
            if element_name in ["st_caption", "st_image"]:
                markdown_container_test_id = "stCaptionContainer"

            element_locator = locator_fn(
                container.get_by_test_id(markdown_container_test_id)
            )

            if feature in disallowed_features:
                # Feature should not be present
                expect(element_locator.first).not_to_be_attached()
            else:
                # Feature should be present
                expect(element_locator.first).to_be_visible()

            if element_name == "st_dialog":
                # Close the dialog
                app.keyboard.press("Escape")
                expect(container).not_to_be_visible()