|
| 1 | +import { test, expect } from "@playwright/test"; |
| 2 | + |
| 3 | +test("[MastraAgentLocal] Backend Tool Rendering displays weather cards", async ({ page }) => { |
| 4 | + // Set shorter default timeout for this test |
| 5 | + test.setTimeout(30000); // 30 seconds total |
| 6 | + |
| 7 | + await page.goto("/langgraph-fastapi/feature/backend_tool_rendering"); |
| 8 | + |
| 9 | + // Verify suggestion buttons are visible |
| 10 | + await expect(page.getByRole("button", { name: "Weather in San Francisco" })).toBeVisible({ |
| 11 | + timeout: 5000, |
| 12 | + }); |
| 13 | + |
| 14 | + // Click first suggestion and verify weather card appears |
| 15 | + await page.getByRole("button", { name: "Weather in San Francisco" }).click(); |
| 16 | + |
| 17 | + // Wait for either test ID or fallback to "Current Weather" text |
| 18 | + const weatherCard = page.getByTestId("weather-card"); |
| 19 | + const currentWeatherText = page.getByText("Current Weather"); |
| 20 | + |
| 21 | + // Try test ID first, fallback to text |
| 22 | + try { |
| 23 | + await expect(weatherCard).toBeVisible({ timeout: 10000 }); |
| 24 | + } catch (e) { |
| 25 | + // Fallback to checking for "Current Weather" text |
| 26 | + await expect(currentWeatherText.first()).toBeVisible({ timeout: 10000 }); |
| 27 | + } |
| 28 | + |
| 29 | + // Verify weather content is present (use flexible selectors) |
| 30 | + const hasHumidity = await page |
| 31 | + .getByText("Humidity") |
| 32 | + .isVisible() |
| 33 | + .catch(() => false); |
| 34 | + const hasWind = await page |
| 35 | + .getByText("Wind") |
| 36 | + .isVisible() |
| 37 | + .catch(() => false); |
| 38 | + const hasCityName = await page |
| 39 | + .locator("h3") |
| 40 | + .filter({ hasText: /San Francisco/i }) |
| 41 | + .isVisible() |
| 42 | + .catch(() => false); |
| 43 | + |
| 44 | + // At least one of these should be true |
| 45 | + expect(hasHumidity || hasWind || hasCityName).toBeTruthy(); |
| 46 | + |
| 47 | + // Click second suggestion |
| 48 | + await page.getByRole("button", { name: "Weather in New York" }).click(); |
| 49 | + await page.waitForTimeout(2000); |
| 50 | + |
| 51 | + // Verify at least one weather-related element is still visible |
| 52 | + const weatherElements = await page.getByText(/Weather|Humidity|Wind|Temperature/i).count(); |
| 53 | + expect(weatherElements).toBeGreaterThan(0); |
| 54 | +}); |
0 commit comments