2
0

sdk-test.spec.ts 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 join RTC channel and test audio transmission", async ({ page }) => {
  88. // 先初始化SDK
  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. // 点击加入RTC频道按钮
  93. await page.click('button:has-text("加入RTC频道")')
  94. // 验证RTC频道加入成功
  95. await expect(page.locator('button:has-text("✅ RTC频道已加入")')).toBeVisible({
  96. timeout: 10000,
  97. })
  98. await expect(page.locator(".logContainer")).toContainText("✅ RTC频道加入成功")
  99. // 点击创建音视频轨道按钮
  100. await page.click('button:has-text("创建音视频轨道")')
  101. // 验证轨道创建成功
  102. await expect(page.locator(".logContainer")).toContainText("✅ 音视频轨道创建成功", {
  103. timeout: 10000,
  104. })
  105. // 点击发布音视频流按钮
  106. await page.click('button:has-text("发布音视频流")')
  107. // 验证流发布成功
  108. await expect(page.locator(".logContainer")).toContainText("✅ 音视频流发布成功", {
  109. timeout: 10000,
  110. })
  111. })
  112. test("should test complete audio transcription with RTC integration", async ({ page }) => {
  113. // 先初始化SDK
  114. await page.fill('input[placeholder="请输入 Agora App ID"]', "test-app-id")
  115. await page.fill('input[placeholder="请输入 Agora Certificate"]', "test-certificate")
  116. await page.click('button:has-text("初始化 SDK")')
  117. // 初始化STT管理器
  118. await page.click('button:has-text("初始化STT管理器")')
  119. // 加入RTC频道
  120. await page.click('button:has-text("加入RTC频道")')
  121. // 开始转录
  122. await page.click('button:has-text("开始转录")')
  123. // 验证转录状态
  124. await expect(page.locator('button:has-text("转录进行中...")')).toBeVisible({ timeout: 10000 })
  125. // 创建音视频轨道
  126. await page.click('button:has-text("创建音视频轨道")')
  127. // 发布音视频流
  128. await page.click('button:has-text("发布音视频流")')
  129. // 验证完整的流程日志
  130. const logText = await page.locator(".logContainer").textContent()
  131. expect(logText).toContain("✅ SDK初始化成功")
  132. expect(logText).toContain("✅ STT管理器初始化成功")
  133. expect(logText).toContain("✅ RTC频道加入成功")
  134. expect(logText).toContain("✅ 语音转录已开始")
  135. expect(logText).toContain("✅ 音视频轨道创建成功")
  136. expect(logText).toContain("✅ 音视频流发布成功")
  137. // 停止转录
  138. await page.click('button:has-text("停止转录")')
  139. // 验证转录停止
  140. await expect(page.locator('button:has-text("开始转录")')).toBeVisible({ timeout: 10000 })
  141. })
  142. test("should cleanup resources properly", async ({ page }) => {
  143. // 先完成所有初始化步骤
  144. await page.fill('input[placeholder="请输入 Agora App ID"]', "test-app-id")
  145. await page.fill('input[placeholder="请输入 Agora Certificate"]', "test-certificate")
  146. await page.click('button:has-text("初始化 SDK")')
  147. await page.click('button:has-text("初始化STT管理器")')
  148. // 点击清理资源按钮
  149. await page.click('button:has-text("清理资源")')
  150. // 验证资源清理成功
  151. await expect(page.locator('button:has-text("初始化 SDK")')).toBeVisible()
  152. await expect(page.locator(".logContainer")).toContainText("✅ 资源清理完成")
  153. })
  154. test("should navigate to main app from SDK test page", async ({ page }) => {
  155. // 点击返回主应用链接
  156. await page.click('button:has-text("返回主应用")')
  157. // 验证导航到登录页面
  158. await expect(page).toHaveURL(/.*\/login/)
  159. })
  160. test("should display test logs correctly", async ({ page }) => {
  161. // 执行一些操作生成日志
  162. await page.fill('input[placeholder="请输入 Agora App ID"]', "test-app-id")
  163. await page.fill('input[placeholder="请输入 Agora Certificate"]', "test-certificate")
  164. await page.click('button:has-text("初始化 SDK")')
  165. // 验证日志容器中有内容
  166. const logContainer = page.locator(".logContainer")
  167. await expect(logContainer).not.toContainText("暂无测试日志")
  168. // 点击清空日志按钮
  169. await page.click('button:has-text("清空日志")')
  170. // 验证日志被清空
  171. await expect(logContainer).toContainText("暂无测试日志")
  172. })
  173. })