from uuid import uuid4 from playwright.sync_api import Page, expect def test_scenario_form_loads(page: Page): """Verify the scenario form page loads correctly.""" page.goto("/ui/scenarios") expect(page).to_have_url( "http://localhost:8001/ui/scenarios" ) # Updated port expect(page.locator("h2:has-text('Create a New Scenario')")).to_be_visible() def test_create_new_scenario(page: Page): """Test creating a new scenario via the UI form.""" page.goto("/ui/scenarios") scenario_name = f"E2E Test Scenario {uuid4()}" scenario_desc = "A scenario created during an end-to-end test." page.fill("input[name='name']", scenario_name) page.fill("input[name='description']", scenario_desc) # Expect a network response from the POST request after clicking the submit button. with page.expect_response("**/api/scenarios/") as response_info: page.click("button[type='submit']") response = response_info.value assert response.status == 200 # After a successful submission, the new scenario should be visible in the table. # The table is dynamically updated, so we might need to wait for it to appear. new_row = page.locator(f"tr:has-text('{scenario_name}')") expect(new_row).to_be_visible() expect(new_row.locator("td").nth(1)).to_have_text(scenario_desc) # Verify the feedback message. feedback = page.locator("#feedback") expect(feedback).to_be_visible() expect(feedback).to_have_text( f'Scenario "{scenario_name}" created successfully.' )