streamlit

Форк
0
/
main_menu_test.py 
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

15
import pytest
16
from playwright.sync_api import Page, expect
17

18
from e2e_playwright.conftest import ImageCompareFunction
19

20

21
def test_main_menu_images(themed_app: Page, assert_snapshot: ImageCompareFunction):
22
    themed_app.get_by_test_id("stMainMenu").click()
23

24
    element = themed_app.get_by_test_id("stMainMenuPopover")
25
    assert_snapshot(element, name="main_menu")
26

27

28
def test_renders_settings_dialog_properly(
29
    themed_app: Page, assert_snapshot: ImageCompareFunction
30
):
31
    themed_app.get_by_test_id("stMainMenu").click()
32

33
    themed_app.get_by_text("Settings").click()
34
    dialog = themed_app.get_by_test_id("stModal")
35
    expect(dialog).to_be_visible()
36
    assert_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")
41
def test_renders_screencast_dialog_properly(
42
    themed_app: Page, assert_snapshot: ImageCompareFunction
43
):
44
    themed_app.get_by_test_id("stMainMenu").click()
45

46
    themed_app.get_by_text("Record a screencast").click()
47
    dialog = themed_app.get_by_test_id("stModal")
48
    expect(dialog).to_be_visible()
49
    assert_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")
54
def test_renders_screencast_recorded_dialog_properly(themed_app: Page):
55
    themed_app.get_by_test_id("stMainMenu").click()
56

57
    themed_app.get_by_text("Record a screencast").click()
58
    themed_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 buffer
61
    themed_app.wait_for_timeout(5000)
62

63
    # stop recording
64
    themed_app.keyboard.press("Escape")
65
    dialog = themed_app.get_by_test_id("stModal")
66
    expect(dialog).to_be_visible()
67

68
    # don't use screenshot as the recording may differ so just check for specific text
69
    expect(
70
        themed_app.get_by_role("dialog").get_by_text("Preview your video below:")
71
    ).to_be_visible
72

73

74
def test_renders_about_dialog_properly(themed_app: Page):
75
    themed_app.get_by_test_id("stMainMenu").click()
76

77
    themed_app.get_by_text("About").click()
78
    dialog = themed_app.get_by_test_id("stModal")
79
    expect(dialog).to_be_visible()
80
    expect(dialog).to_contain_text("Made with Streamlit v")
81

82

83
def test_renders_clear_cache_dialog_properly(
84
    themed_app: Page, assert_snapshot: ImageCompareFunction
85
):
86
    themed_app.get_by_test_id("stMainMenu").click()
87

88
    themed_app.get_by_text("Clear cache").click()
89
    dialog = themed_app.get_by_test_id("stModal")
90
    expect(dialog).to_be_visible()
91
    expect(dialog).to_contain_text(
92
        "Are you sure you want to clear the app's function caches?"
93
    )
94
    assert_snapshot(dialog.get_by_role("dialog"), name="clear_cache_dialog")
95

96

97
def test_renders_active_theme_dialog_properly(
98
    themed_app: Page, assert_snapshot: ImageCompareFunction
99
):
100
    themed_app.get_by_test_id("stMainMenu").click()
101
    themed_app.get_by_text("Settings").click()
102
    themed_app.get_by_text("Edit active theme").click()
103

104
    dialog = themed_app.get_by_test_id("stModal")
105
    expect(dialog).to_be_visible()
106

107
    assert_snapshot(dialog.get_by_role("dialog"), name="edit_active_theme_dialog")
108

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.