sdk-test.spec.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { test, expect } from "@playwright/test"
  2. test.describe("SDK Test Page E2E Tests", () => {
  3. test.beforeEach(async ({ page }) => {
  4. // 导航到SDK测试页面
  5. await page.goto("/sdk-test")
  6. })
  7. test("should load SDK test page successfully", async ({ page }) => {
  8. // 验证页面标题
  9. await expect(page.locator("h2")).toContainText("SDK 功能测试页面")
  10. // 验证配置表单存在
  11. await expect(page.locator('input[placeholder="请输入 Agora App ID"]')).toBeVisible()
  12. await expect(page.locator('input[placeholder="请输入 Agora Certificate"]')).toBeVisible()
  13. await expect(page.locator('input[placeholder="请输入频道名称"]')).toBeVisible()
  14. await expect(page.locator('input[placeholder="请输入用户名称"]')).toBeVisible()
  15. })
  16. test("should initialize SDK with valid credentials", async ({ page }) => {
  17. // 填写配置信息
  18. await page.fill('input[placeholder="请输入 Agora App ID"]', "test-app-id")
  19. await page.fill('input[placeholder="请输入 Agora Certificate"]', "test-certificate")
  20. // 点击初始化SDK按钮
  21. await page.click('button:has-text("初始化 SDK")')
  22. // 验证初始化成功
  23. await expect(page.locator('button:has-text("✅ 已初始化")')).toBeVisible()
  24. // 验证测试日志显示初始化成功
  25. await expect(page.locator(".logContainer")).toContainText("✅ SDK初始化成功")
  26. })
  27. test("should show error message with invalid credentials", async ({ page }) => {
  28. // 填写空的配置信息
  29. await page.fill('input[placeholder="请输入 Agora App ID"]', "")
  30. await page.fill('input[placeholder="请输入 Agora Certificate"]', "")
  31. // 点击初始化SDK按钮
  32. await page.click('button:has-text("初始化 SDK")')
  33. // 验证错误消息显示
  34. await expect(page.locator(".ant-message-error")).toBeVisible()
  35. })
  36. test("should initialize STT manager after SDK initialization", async ({ page }) => {
  37. // 先初始化SDK
  38. await page.fill('input[placeholder="请输入 Agora App ID"]', "test-app-id")
  39. await page.fill('input[placeholder="请输入 Agora Certificate"]', "test-certificate")
  40. await page.click('button:has-text("初始化 SDK")')
  41. // 点击初始化STT管理器按钮
  42. await page.click('button:has-text("初始化STT管理器")')
  43. // 验证STT管理器初始化成功
  44. await expect(page.locator('button:has-text("✅ STT管理器已初始化")')).toBeVisible()
  45. await expect(page.locator(".logContainer")).toContainText("✅ STT管理器初始化成功")
  46. })
  47. test("should join RTM channel successfully", async ({ page }) => {
  48. // 先初始化SDK
  49. await page.fill('input[placeholder="请输入 Agora App ID"]', "test-app-id")
  50. await page.fill('input[placeholder="请输入 Agora Certificate"]', "test-certificate")
  51. await page.click('button:has-text("初始化 SDK")')
  52. // 点击加入RTM频道按钮
  53. await page.click('button:has-text("加入RTM频道")')
  54. // 验证RTM频道加入成功
  55. await expect(page.locator('button:has-text("✅ RTM频道已加入")')).toBeVisible()
  56. await expect(page.locator(".logContainer")).toContainText("✅ RTM频道加入成功")
  57. })
  58. test("should start and stop transcription", async ({ page }) => {
  59. // 先完成所有初始化步骤
  60. await page.fill('input[placeholder="请输入 Agora App ID"]', "test-app-id")
  61. await page.fill('input[placeholder="请输入 Agora Certificate"]', "test-certificate")
  62. await page.click('button:has-text("初始化 SDK")')
  63. await page.click('button:has-text("初始化STT管理器")')
  64. // 点击开始转录按钮
  65. await page.click('button:has-text("开始转录")')
  66. // 验证转录状态
  67. await expect(page.locator('button:has-text("转录进行中...")')).toBeVisible()
  68. await expect(page.locator(".logContainer")).toContainText("✅ 语音转录已开始")
  69. // 点击停止转录按钮
  70. await page.click('button:has-text("停止转录")')
  71. // 验证转录已停止
  72. await expect(page.locator('button:has-text("开始转录")')).toBeVisible()
  73. await expect(page.locator(".logContainer")).toContainText("✅ 语音转录已停止")
  74. })
  75. test("should query transcription status", async ({ page }) => {
  76. // 先完成所有初始化步骤并开始转录
  77. await page.fill('input[placeholder="请输入 Agora App ID"]', "test-app-id")
  78. await page.fill('input[placeholder="请输入 Agora Certificate"]', "test-certificate")
  79. await page.click('button:has-text("初始化 SDK")')
  80. await page.click('button:has-text("初始化STT管理器")')
  81. await page.click('button:has-text("开始转录")')
  82. // 点击查询状态按钮
  83. await page.click('button:has-text("查询状态")')
  84. // 验证查询结果日志
  85. await expect(page.locator(".logContainer")).toContainText("📊 转录状态查询结果")
  86. })
  87. test("should cleanup resources properly", async ({ page }) => {
  88. // 先完成所有初始化步骤
  89. await page.fill('input[placeholder="请输入 Agora App ID"]', "test-app-id")
  90. await page.fill('input[placeholder="请输入 Agora Certificate"]', "test-certificate")
  91. await page.click('button:has-text("初始化 SDK")')
  92. await page.click('button:has-text("初始化STT管理器")')
  93. // 点击清理资源按钮
  94. await page.click('button:has-text("清理资源")')
  95. // 验证资源清理成功
  96. await expect(page.locator('button:has-text("初始化 SDK")')).toBeVisible()
  97. await expect(page.locator(".logContainer")).toContainText("✅ 资源清理完成")
  98. })
  99. test("should navigate to main app from SDK test page", async ({ page }) => {
  100. // 点击返回主应用链接
  101. await page.click('button:has-text("返回主应用")')
  102. // 验证导航到登录页面
  103. await expect(page).toHaveURL(/.*\/login/)
  104. })
  105. test("should display test logs correctly", async ({ page }) => {
  106. // 执行一些操作生成日志
  107. await page.fill('input[placeholder="请输入 Agora App ID"]', "test-app-id")
  108. await page.fill('input[placeholder="请输入 Agora Certificate"]', "test-certificate")
  109. await page.click('button:has-text("初始化 SDK")')
  110. // 验证日志容器中有内容
  111. const logContainer = page.locator(".logContainer")
  112. await expect(logContainer).not.toContainText("暂无测试日志")
  113. // 点击清空日志按钮
  114. await page.click('button:has-text("清空日志")')
  115. // 验证日志被清空
  116. await expect(logContainer).toContainText("暂无测试日志")
  117. })
  118. })