streamlit

Форк
0
/
st_camera_input_test.py 
61 строка · 2.5 Кб
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
import pytest
15
from playwright.sync_api import Page, expect
16

17
from e2e_playwright.conftest import ImageCompareFunction
18

19

20
@pytest.mark.skip_browser("webkit")
21
def test_displays_correct_number_of_elements(app: Page):
22
    """Test that it renders correct number of camera_input elements."""
23
    camera_input_widgets = app.get_by_test_id("stCameraInput")
24
    expect(camera_input_widgets).to_have_count(2)
25

26

27
@pytest.mark.only_browser("chromium")
28
def test_captures_photo(app: Page):
29
    """Test camera_input captures photo when 'Take photo' button clicked."""
30
    # Wait for some timeout, until fake video stream available for camera_input
31
    app.wait_for_timeout(3000)
32
    take_photo_button = app.get_by_test_id("stCameraInputButton").first
33
    # Capture a photo
34
    take_photo_button.click()
35
    expect(app.get_by_test_id("stImage")).to_have_count(1)
36

37

38
@pytest.mark.only_browser("chromium")
39
def test_clear_photo(app: Page):
40
    """Test camera_input removes photo when 'Clear photo' button clicked."""
41
    # Wait for some timeout, until fake video stream available for camera_input
42
    app.wait_for_timeout(3000)
43
    take_photo_button = app.get_by_test_id("stCameraInputButton").first
44
    # Capture a photo
45
    take_photo_button.click()
46
    expect(app.get_by_test_id("stImage")).to_have_count(1)
47
    remove_photo_button = app.get_by_text("Clear photo").first
48
    remove_photo_button.click()
49
    expect(app.get_by_test_id("stImage")).to_have_count(0)
50

51

52
@pytest.mark.skip_browser("webkit")
53
def test_shows_disabled_widget_correctly(
54
    themed_app: Page,
55
    assert_snapshot: ImageCompareFunction,
56
):
57
    """Test that it renders disabled camera_input widget correctly."""
58
    camera_input_widgets = themed_app.get_by_test_id("stCameraInput")
59
    expect(camera_input_widgets).to_have_count(2)
60
    disabled_camera_input = camera_input_widgets.nth(1)
61
    assert_snapshot(disabled_camera_input, name="st_camera_input-disabled")
62

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

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

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

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