import { test, expect } from "@playwright/test" test.describe("SDK Test Page E2E Tests", () => { test.beforeEach(async ({ page }) => { // 导航到SDK测试页面 await page.goto("/sdk-test") }) test("should load SDK test page successfully", async ({ page }) => { // 验证页面标题 await expect(page.locator("h2")).toContainText("SDK 功能测试页面") // 验证配置表单存在 await expect(page.locator('input[placeholder="请输入 Agora App ID"]')).toBeVisible() await expect(page.locator('input[placeholder="请输入 Agora Certificate"]')).toBeVisible() await expect(page.locator('input[placeholder="请输入频道名称"]')).toBeVisible() await expect(page.locator('input[placeholder="请输入用户名称"]')).toBeVisible() }) test("should initialize SDK with valid credentials", async ({ page }) => { // 填写配置信息 await page.fill('input[placeholder="请输入 Agora App ID"]', "test-app-id") await page.fill('input[placeholder="请输入 Agora Certificate"]', "test-certificate") // 点击初始化SDK按钮 await page.click('button:has-text("初始化 SDK")') // 验证初始化成功 await expect(page.locator('button:has-text("✅ 已初始化")')).toBeVisible() // 验证测试日志显示初始化成功 await expect(page.locator(".logContainer")).toContainText("✅ SDK初始化成功") }) test("should show error message with invalid credentials", async ({ page }) => { // 填写空的配置信息 await page.fill('input[placeholder="请输入 Agora App ID"]', "") await page.fill('input[placeholder="请输入 Agora Certificate"]', "") // 点击初始化SDK按钮 await page.click('button:has-text("初始化 SDK")') // 验证错误消息显示 await expect(page.locator(".ant-message-error")).toBeVisible() }) test("should initialize STT manager after SDK initialization", async ({ page }) => { // 先初始化SDK await page.fill('input[placeholder="请输入 Agora App ID"]', "test-app-id") await page.fill('input[placeholder="请输入 Agora Certificate"]', "test-certificate") await page.click('button:has-text("初始化 SDK")') // 点击初始化STT管理器按钮 await page.click('button:has-text("初始化STT管理器")') // 验证STT管理器初始化成功 await expect(page.locator('button:has-text("✅ STT管理器已初始化")')).toBeVisible() await expect(page.locator(".logContainer")).toContainText("✅ STT管理器初始化成功") }) test("should join RTM channel successfully", async ({ page }) => { // 先初始化SDK await page.fill('input[placeholder="请输入 Agora App ID"]', "test-app-id") await page.fill('input[placeholder="请输入 Agora Certificate"]', "test-certificate") await page.click('button:has-text("初始化 SDK")') // 点击加入RTM频道按钮 await page.click('button:has-text("加入RTM频道")') // 验证RTM频道加入成功 await expect(page.locator('button:has-text("✅ RTM频道已加入")')).toBeVisible() await expect(page.locator(".logContainer")).toContainText("✅ RTM频道加入成功") }) test("should start and stop transcription", async ({ page }) => { // 先完成所有初始化步骤 await page.fill('input[placeholder="请输入 Agora App ID"]', "test-app-id") await page.fill('input[placeholder="请输入 Agora Certificate"]', "test-certificate") await page.click('button:has-text("初始化 SDK")') await page.click('button:has-text("初始化STT管理器")') // 点击开始转录按钮 await page.click('button:has-text("开始转录")') // 验证转录状态 await expect(page.locator('button:has-text("转录进行中...")')).toBeVisible() await expect(page.locator(".logContainer")).toContainText("✅ 语音转录已开始") // 点击停止转录按钮 await page.click('button:has-text("停止转录")') // 验证转录已停止 await expect(page.locator('button:has-text("开始转录")')).toBeVisible() await expect(page.locator(".logContainer")).toContainText("✅ 语音转录已停止") }) test("should query transcription status", async ({ page }) => { // 先完成所有初始化步骤并开始转录 await page.fill('input[placeholder="请输入 Agora App ID"]', "test-app-id") await page.fill('input[placeholder="请输入 Agora Certificate"]', "test-certificate") await page.click('button:has-text("初始化 SDK")') await page.click('button:has-text("初始化STT管理器")') await page.click('button:has-text("开始转录")') // 点击查询状态按钮 await page.click('button:has-text("查询状态")') // 验证查询结果日志 await expect(page.locator(".logContainer")).toContainText("📊 转录状态查询结果") }) test("should cleanup resources properly", async ({ page }) => { // 先完成所有初始化步骤 await page.fill('input[placeholder="请输入 Agora App ID"]', "test-app-id") await page.fill('input[placeholder="请输入 Agora Certificate"]', "test-certificate") await page.click('button:has-text("初始化 SDK")') await page.click('button:has-text("初始化STT管理器")') // 点击清理资源按钮 await page.click('button:has-text("清理资源")') // 验证资源清理成功 await expect(page.locator('button:has-text("初始化 SDK")')).toBeVisible() await expect(page.locator(".logContainer")).toContainText("✅ 资源清理完成") }) test("should navigate to main app from SDK test page", async ({ page }) => { // 点击返回主应用链接 await page.click('button:has-text("返回主应用")') // 验证导航到登录页面 await expect(page).toHaveURL(/.*\/login/) }) test("should display test logs correctly", async ({ page }) => { // 执行一些操作生成日志 await page.fill('input[placeholder="请输入 Agora App ID"]', "test-app-id") await page.fill('input[placeholder="请输入 Agora Certificate"]', "test-certificate") await page.click('button:has-text("初始化 SDK")') // 验证日志容器中有内容 const logContainer = page.locator(".logContainer") await expect(logContainer).not.toContainText("暂无测试日志") // 点击清空日志按钮 await page.click('button:has-text("清空日志")') // 验证日志被清空 await expect(logContainer).toContainText("暂无测试日志") }) })