Skip to content

Commit

Permalink
Migrate set_page_config e2e test to playwright (streamlit#9308)
Browse files Browse the repository at this point in the history
## Describe your changes

Migrates the `set_page_config` e2e test from cypress to playwright and
extend test coverage to additional parameters.

## Testing Plan

- Migrated e2e test

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
  • Loading branch information
lukasmasuch authored Aug 20, 2024
1 parent 05ba3b6 commit 98047af
Show file tree
Hide file tree
Showing 9 changed files with 264 additions and 210 deletions.
62 changes: 0 additions & 62 deletions e2e/scripts/st_set_page_config.py

This file was deleted.

90 changes: 0 additions & 90 deletions e2e/specs/st_set_page_config.spec.js

This file was deleted.

19 changes: 14 additions & 5 deletions e2e_playwright/shared/app_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def expect_markdown(

def expect_exception(
locator: Locator | Page,
expected_message: str | Pattern[str],
expected_message: str | Pattern[str] | None = None,
) -> None:
"""Expect an exception to be displayed in the app.
Expand All @@ -260,15 +260,24 @@ def expect_exception(
locator : Locator
The locator to search for the exception element.
expected_message : str or Pattern[str]
expected_message : str or Pattern[str] or None
The expected message to be displayed in the exception.
"""
exception_el = locator.get_by_test_id("stException").filter(
has_text=expected_message
)

if expected_message is None:
exception_el = locator.get_by_test_id("stException")
else:
exception_el = locator.get_by_test_id("stException").filter(
has_text=expected_message
)
expect(exception_el).to_be_visible()


def expect_no_exception(locator: Locator | Page):
exception_el = locator.get_by_test_id("stException")
expect(exception_el).not_to_be_attached()


def expect_warning(
locator: Locator | Page,
expected_message: str | Pattern[str],
Expand Down
119 changes: 119 additions & 0 deletions e2e_playwright/st_set_page_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

import streamlit as st

# Construct test assets path relative to this script file to
# allow its execution with different working directories.
TEST_ASSETS_DIR = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "test_assets"
)

st.sidebar.button("Sidebar!")
st.markdown("Main!")
with st.expander("Expander in main"):
st.write("Text in expander")


def preceding_command_in_callback():
st.balloons()
st.set_page_config(page_title="Allows preceding command in callback")


st.button("Preceding Command in Callback", on_click=preceding_command_in_callback)


def collapsed_sidebar():
st.set_page_config(
page_title="Collapsed Sidebar", initial_sidebar_state="collapsed"
)


st.button("Collapsed Sidebar", on_click=collapsed_sidebar)


def expanded_sidebar():
st.set_page_config(page_title="Expanded Sidebar", initial_sidebar_state="expanded")


st.button("Expanded Sidebar", on_click=expanded_sidebar)


def wide_layout():
st.set_page_config(page_title="Wide Layout", layout="wide")


st.button("Wide Layout", on_click=wide_layout)


def centered_layout():
st.set_page_config(page_title="Centered Layout", layout="centered")


st.button("Centered Layout", on_click=centered_layout)


def double_set_page_config():
st.set_page_config(page_title="Page Config 1")
st.set_page_config(page_title="Page Config 2")


st.button("Double Set Page Config", on_click=double_set_page_config)


def page_config_with_emoji_shortcode():
st.set_page_config(
page_title="With Emoji Shortcode",
page_icon=":shark:",
)


st.button("Page Config With Emoji Shortcode", on_click=page_config_with_emoji_shortcode)


def page_config_with_emoji_symbol():
st.set_page_config(
page_title="With Emoji Symbol",
page_icon="🐙",
)


st.button("Page Config With Emoji Symbol", on_click=page_config_with_emoji_symbol)


def page_config_with_local_icon():
ICON_PATH = os.path.join(TEST_ASSETS_DIR, "favicon.ico")

st.set_page_config(
page_title="With Local Icon",
page_icon=ICON_PATH,
)


st.button("Page Config With Local Icon", on_click=page_config_with_local_icon)


def page_config_with_material_icon():
st.set_page_config(
page_title="With Material Icon",
page_icon=":material/thumb_up:",
)


st.button("Page Config With Material Icon", on_click=page_config_with_material_icon)

# The menu_items parameter is covered by the `main_menu.py` script
# initial_sidebar_state = auto is covered by the `st_sidebar.py` script
26 changes: 0 additions & 26 deletions e2e_playwright/st_set_page_config_icon.py

This file was deleted.

27 changes: 0 additions & 27 deletions e2e_playwright/st_set_page_config_icon_test.py

This file was deleted.

Loading

0 comments on commit 98047af

Please sign in to comment.