streamlit
107 строк · 3.8 Кб
1# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import pytest16from playwright.sync_api import Page, expect17
18from e2e_playwright.conftest import ImageCompareFunction19
20
21def test_main_menu_images(themed_app: Page, assert_snapshot: ImageCompareFunction):22themed_app.get_by_test_id("stMainMenu").click()23
24element = themed_app.get_by_test_id("stMainMenuPopover")25assert_snapshot(element, name="main_menu")26
27
28def test_renders_settings_dialog_properly(29themed_app: Page, assert_snapshot: ImageCompareFunction30):31themed_app.get_by_test_id("stMainMenu").click()32
33themed_app.get_by_text("Settings").click()34dialog = themed_app.get_by_test_id("stModal")35expect(dialog).to_be_visible()36assert_snapshot(dialog.get_by_role("dialog"), name="settings_dialog")37
38
39# Webkit (safari) and firefox doesn't support screencast on linux machines
40@pytest.mark.only_browser("chromium")41def test_renders_screencast_dialog_properly(42themed_app: Page, assert_snapshot: ImageCompareFunction43):44themed_app.get_by_test_id("stMainMenu").click()45
46themed_app.get_by_text("Record a screencast").click()47dialog = themed_app.get_by_test_id("stModal")48expect(dialog).to_be_visible()49assert_snapshot(dialog.get_by_role("dialog"), name="record_screencast_dialog")50
51
52# Webkit (safari) and firefox doesn't support screencast on linux machines
53@pytest.mark.only_browser("chromium")54def test_renders_screencast_recorded_dialog_properly(themed_app: Page):55themed_app.get_by_test_id("stMainMenu").click()56
57themed_app.get_by_text("Record a screencast").click()58themed_app.get_by_text("Start recording!").click()59
60# Wait 5 seconds because there is a 3! 2! 1! on the screen until recording occurs and there may be buffer61themed_app.wait_for_timeout(5000)62
63# stop recording64themed_app.keyboard.press("Escape")65dialog = themed_app.get_by_test_id("stModal")66expect(dialog).to_be_visible()67
68# don't use screenshot as the recording may differ so just check for specific text69expect(70themed_app.get_by_role("dialog").get_by_text("Preview your video below:")71).to_be_visible72
73
74def test_renders_about_dialog_properly(themed_app: Page):75themed_app.get_by_test_id("stMainMenu").click()76
77themed_app.get_by_text("About").click()78dialog = themed_app.get_by_test_id("stModal")79expect(dialog).to_be_visible()80expect(dialog).to_contain_text("Made with Streamlit v")81
82
83def test_renders_clear_cache_dialog_properly(84themed_app: Page, assert_snapshot: ImageCompareFunction85):86themed_app.get_by_test_id("stMainMenu").click()87
88themed_app.get_by_text("Clear cache").click()89dialog = themed_app.get_by_test_id("stModal")90expect(dialog).to_be_visible()91expect(dialog).to_contain_text(92"Are you sure you want to clear the app's function caches?"93)94assert_snapshot(dialog.get_by_role("dialog"), name="clear_cache_dialog")95
96
97def test_renders_active_theme_dialog_properly(98themed_app: Page, assert_snapshot: ImageCompareFunction99):100themed_app.get_by_test_id("stMainMenu").click()101themed_app.get_by_text("Settings").click()102themed_app.get_by_text("Edit active theme").click()103
104dialog = themed_app.get_by_test_id("stModal")105expect(dialog).to_be_visible()106
107assert_snapshot(dialog.get_by_role("dialog"), name="edit_active_theme_dialog")108