Spaces:
Runtime error
Runtime error
File size: 2,352 Bytes
d4167d9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
import pytest
import os
from playwright.sync_api import expect
from PIL import Image
import numpy as np
import tempfile
# Constants
GRADIO_PORT = 7862
GRADIO_URL = f"http://localhost:{GRADIO_PORT}"
@pytest.fixture(scope="module")
def test_image():
# Create a temporary test image
test_img = Image.fromarray(np.zeros((100, 100, 3), dtype=np.uint8))
temp_dir = tempfile.mkdtemp()
test_img_path = os.path.join(temp_dir, "test_image.png")
test_img.save(test_img_path)
yield test_img_path
# Cleanup
os.remove(test_img_path)
os.rmdir(temp_dir)
def test_page_loads(page):
page.goto(GRADIO_URL)
page.wait_for_load_state("networkidle")
# Check if title is present with exact text
expect(page.locator("h2", has_text="Crowdsourcing Handwriting OCR Dataset")).to_be_visible()
# Check if main interface elements are present
expect(page.get_by_label("Text to Handwrite")).to_be_visible()
expect(page.locator('input[type="file"]')).to_be_attached()
expect(page.get_by_role("button", name="Submit")).to_be_visible()
expect(page.get_by_role("button", name="Skip")).to_be_visible()
def test_skip_functionality(page):
page.goto(GRADIO_URL)
page.wait_for_load_state("networkidle")
# Get initial text
text_box = page.get_by_label("Text to Handwrite")
initial_text = text_box.input_value()
# Click skip button
page.get_by_role("button", name="Skip").click()
page.wait_for_timeout(2000) # Wait for response
# Get new text and verify it changed
new_text = text_box.input_value()
assert initial_text != new_text
def test_upload_image(page, test_image):
page.goto(GRADIO_URL)
page.wait_for_load_state("networkidle")
# Get initial text
text_box = page.get_by_label("Text to Handwrite")
initial_text = text_box.input_value()
# Upload image - file input is hidden, but we can still set its value
page.locator('input[type="file"]').set_input_files(test_image)
page.wait_for_timeout(2000) # Wait for upload
# Click submit to complete the upload
page.get_by_role("button", name="Submit").click()
page.wait_for_timeout(2000) # Wait for response
# Verify text changed after submission
new_text = text_box.input_value()
assert initial_text != new_text |