forked from streamlit/streamlit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate MPA e2e test to playwright (streamlit#7859)
* Migrate mpa e2e test * Add copyright header * Add snapshots * Remove unneeded snapshots * Add missing snapshot * Update test * Update snapshots * Revert commit * Revert snapshots * Revert snapshot * Remove wrong snapshot * Add early execution fixture * Exclude all pytest ini files * Clear config option * Update copyright headers * Remove snapshot * Update webkit snapshot * Update snapshot
- Loading branch information
1 parent
3eb3f84
commit 4927708
Showing
31 changed files
with
228 additions
and
123 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Binary file added
BIN
+11.9 KB
...ht/__snapshots__/linux/mpa_basics_test/mpa-sidebar_nav[dark_theme-chromium].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15 KB
...ght/__snapshots__/linux/mpa_basics_test/mpa-sidebar_nav[dark_theme-firefox].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.8 KB
...ight/__snapshots__/linux/mpa_basics_test/mpa-sidebar_nav[dark_theme-webkit].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.8 KB
...t/__snapshots__/linux/mpa_basics_test/mpa-sidebar_nav[light_theme-chromium].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.5 KB
...ht/__snapshots__/linux/mpa_basics_test/mpa-sidebar_nav[light_theme-firefox].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.7 KB
...ght/__snapshots__/linux/mpa_basics_test/mpa-sidebar_nav[light_theme-webkit].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.06 KB
...ght/__snapshots__/linux/mpa_basics_test/mpa-sidebar_nav_collapsed[chromium].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.31 KB
...ight/__snapshots__/linux/mpa_basics_test/mpa-sidebar_nav_collapsed[firefox].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.68 KB
...right/__snapshots__/linux/mpa_basics_test/mpa-sidebar_nav_collapsed[webkit].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.1 KB
...ight/__snapshots__/linux/mpa_basics_test/mpa-sidebar_nav_expanded[chromium].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.5 KB
...right/__snapshots__/linux/mpa_basics_test/mpa-sidebar_nav_expanded[firefox].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11 KB
...wright/__snapshots__/linux/mpa_basics_test/mpa-sidebar_nav_expanded[webkit].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# 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. |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# 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. | ||
|
||
from playwright.sync_api import Page, expect | ||
|
||
from e2e_playwright.conftest import ( | ||
ImageCompareFunction, | ||
wait_for_app_loaded, | ||
wait_for_app_run, | ||
) | ||
|
||
|
||
def test_loads_main_script_on_initial_page_load(app: Page): | ||
"""Test that the main script is loaded on initial page load.""" | ||
expect(app.get_by_test_id("stHeading")).to_contain_text("Main Page") | ||
|
||
|
||
def test_renders_sidebar_nav_correctly( | ||
themed_app: Page, assert_snapshot: ImageCompareFunction | ||
): | ||
"""Test that the sidebar nav is rendered correctly.""" | ||
assert_snapshot(themed_app.get_by_test_id("stSidebarNav"), name="mpa-sidebar_nav") | ||
|
||
|
||
def test_can_switch_between_pages_by_clicking_on_sidebar_links(app: Page): | ||
"""Test that we can switch between pages by clicking on sidebar links.""" | ||
app.get_by_test_id("stSidebarNav").locator("a").nth(1).click() | ||
wait_for_app_run(app) | ||
expect(app.get_by_test_id("stHeading")).to_contain_text("Page 2") | ||
|
||
|
||
def test_supports_navigating_to_page_directly_via_url(page: Page, app_port: int): | ||
"""Test that we can navigate to a page directly via URL.""" | ||
page.goto(f"http://localhost:{app_port}/page2") | ||
wait_for_app_loaded(page) | ||
|
||
expect(page.get_by_test_id("stHeading")).to_contain_text("Page 2") | ||
|
||
|
||
def test_can_switch_between_pages_and_edit_widgets(app: Page): | ||
"""Test that we can switch between pages and edit widgets.""" | ||
slider = app.locator('.stSlider [role="slider"]') | ||
slider.click() | ||
slider.press("ArrowRight") | ||
wait_for_app_run(app, wait_delay=500) | ||
|
||
app.get_by_test_id("stSidebarNav").locator("a").nth(2).click() | ||
wait_for_app_run(app, wait_delay=1000) | ||
|
||
expect(app.get_by_test_id("stHeading")).to_contain_text("Page 3") | ||
expect(app.get_by_test_id("stMarkdown")).to_contain_text("x is 0") | ||
|
||
slider.click() | ||
slider.press("ArrowRight") | ||
wait_for_app_run(app) | ||
|
||
expect(app.get_by_test_id("stMarkdown")).to_contain_text("x is 1") | ||
|
||
|
||
def test_can_switch_to_the_first_page_with_a_duplicate_name(app: Page): | ||
"""Test that we can switch to the first page with a duplicate name.""" | ||
app.get_by_test_id("stSidebarNav").locator("a").nth(3).click() | ||
wait_for_app_run(app) | ||
expect(app.get_by_test_id("stHeading")).to_contain_text("Page 4") | ||
|
||
|
||
def test_can_switch_to_the_second_page_with_a_duplicate_name(app: Page): | ||
"""Test that we can switch to the second page with a duplicate name.""" | ||
app.get_by_test_id("stSidebarNav").locator("a").nth(4).click() | ||
wait_for_app_run(app) | ||
expect(app.get_by_test_id("stHeading")).to_contain_text("Page 5") | ||
|
||
|
||
def test_runs_the_first_page_with_a_duplicate_name_if_navigating_via_url( | ||
page: Page, app_port: int | ||
): | ||
"""Test that we run the first page with a duplicate name if navigating via URL.""" | ||
page.goto(f"http://localhost:{app_port}/page_with_duplicate_name") | ||
wait_for_app_loaded(page) | ||
|
||
expect(page.get_by_test_id("stHeading")).to_contain_text("Page 4") | ||
|
||
|
||
def test_show_not_found_dialog(page: Page, app_port: int): | ||
"""Test that we show a not found dialog if the page doesn't exist.""" | ||
page.goto(f"http://localhost:{app_port}/not_a_page") | ||
wait_for_app_loaded(page) | ||
|
||
expect(page.locator('[role="dialog"]')).to_contain_text("Page not found") | ||
|
||
|
||
def test_handles_expand_collapse_of_mpa_nav_correctly( | ||
page: Page, app_port: int, assert_snapshot: ImageCompareFunction | ||
): | ||
"""Test that we handle expand/collapse of MPA nav correctly.""" | ||
|
||
page.goto(f"http://localhost:{app_port}/page_7") | ||
wait_for_app_loaded(page) | ||
|
||
separator = page.get_by_test_id("stSidebarNavSeparator") | ||
svg = separator.locator("svg") | ||
|
||
# Expand the nav | ||
svg.click() | ||
assert_snapshot( | ||
page.get_by_test_id("stSidebarNav"), name="mpa-sidebar_nav_expanded" | ||
) | ||
|
||
# Collapse the nav | ||
svg.click() | ||
assert_snapshot( | ||
page.get_by_test_id("stSidebarNav"), name="mpa-sidebar_nav_collapsed" | ||
) | ||
|
||
# Expand the nav again | ||
svg.click() | ||
assert_snapshot( | ||
page.get_by_test_id("stSidebarNav"), name="mpa-sidebar_nav_expanded" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# 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 streamlit as st | ||
|
||
st.header("App with no sidebar") |
34 changes: 34 additions & 0 deletions
34
e2e_playwright/multipage_apps/mpa_configure_sidebar_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# 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 pytest | ||
from playwright.sync_api import Page, expect | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
@pytest.mark.early | ||
def configure_hide_sidebar_nav(): | ||
"""Configure ui.hideSidebarNav=True.""" | ||
# We need to do this in a package scope fixture to ensure that its applied | ||
# before the app server is started. | ||
os.environ["STREAMLIT_UI_HIDE_SIDEBAR_NAV"] = "True" | ||
yield | ||
del os.environ["STREAMLIT_UI_HIDE_SIDEBAR_NAV"] | ||
|
||
|
||
def test_hides_sidebar_nav(app: Page, configure_hide_sidebar_nav): | ||
"""Test that ui.hideSidebarNav=True hides the sidebar.""" | ||
expect(app.get_by_test_id("stSidebar")).not_to_be_attached() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,4 @@ | |
|
||
st.header("Page 3") | ||
x = st.slider("x") | ||
st.write(f"x is {x}") | ||
st.markdown(f"x is {x}") |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[pytest] | ||
markers = | ||
early: prioritize the execution of a fixture | ||
filterwarnings = | ||
# PyTest filter syntax cheatsheet -> action:message:category:module:line | ||
ignore::UserWarning:altair.*: | ||
ignore::DeprecationWarning:flatbuffers.*: | ||
ignore::DeprecationWarning:keras_preprocessing.*: |
Binary file removed
BIN
-13.8 KB
...pshots/linux/2x/multipage_apps.spec.js/multipage-apps-sidebar-nav-dark.snap.png
Binary file not shown.
Binary file removed
BIN
-13.9 KB
...s/snapshots/linux/2x/multipage_apps.spec.js/multipage-apps-sidebar-nav.snap.png
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters