streamlit
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.
14import pytest15from playwright.sync_api import Page, expect16
17from e2e_playwright.conftest import ImageCompareFunction18
19
20@pytest.mark.skip_browser("webkit")21def test_displays_correct_number_of_elements(app: Page):22"""Test that it renders correct number of camera_input elements."""23camera_input_widgets = app.get_by_test_id("stCameraInput")24expect(camera_input_widgets).to_have_count(2)25
26
27@pytest.mark.only_browser("chromium")28def 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_input31app.wait_for_timeout(3000)32take_photo_button = app.get_by_test_id("stCameraInputButton").first33# Capture a photo34take_photo_button.click()35expect(app.get_by_test_id("stImage")).to_have_count(1)36
37
38@pytest.mark.only_browser("chromium")39def 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_input42app.wait_for_timeout(3000)43take_photo_button = app.get_by_test_id("stCameraInputButton").first44# Capture a photo45take_photo_button.click()46expect(app.get_by_test_id("stImage")).to_have_count(1)47remove_photo_button = app.get_by_text("Clear photo").first48remove_photo_button.click()49expect(app.get_by_test_id("stImage")).to_have_count(0)50
51
52@pytest.mark.skip_browser("webkit")53def test_shows_disabled_widget_correctly(54themed_app: Page,55assert_snapshot: ImageCompareFunction,56):57"""Test that it renders disabled camera_input widget correctly."""58camera_input_widgets = themed_app.get_by_test_id("stCameraInput")59expect(camera_input_widgets).to_have_count(2)60disabled_camera_input = camera_input_widgets.nth(1)61assert_snapshot(disabled_camera_input, name="st_camera_input-disabled")62