25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

41 lines
2.6 KiB

  1. import fs from 'node:fs'
  2. import path from 'node:path'
  3. import { fileURLToPath } from 'node:url'
  4. import { createRequire } from 'node:module'
  5. import assert from 'node:assert/strict'
  6. const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../..')
  7. const require = createRequire(path.join(root, 'ai_person/ape2e/package.json'))
  8. const { chromium, expect } = require('@playwright/test')
  9. const report = path.join(root, 'unreal_tran/ute2e/reports/open-platform-pdf-20260909')
  10. fs.mkdirSync(report, { recursive: true })
  11. const browser = await chromium.launch({ channel: 'msedge', headless: true })
  12. try {
  13. const page = await browser.newPage({ viewport: { width: 1600, height: 1000 } })
  14. const errors = []
  15. page.on('pageerror', error => errors.push(error.message))
  16. await page.goto('http://127.0.0.1:8003/developer')
  17. await expect(page.locator('.endpoint-section')).toHaveCount(13)
  18. const button = page.getByRole('button', { name: '导出 PDF', exact: true })
  19. const downloadPromise = page.waitForEvent('download')
  20. await button.click()
  21. const download = await downloadPromise
  22. assert.equal(download.suggestedFilename(), 'digital-human-open-api.pdf')
  23. await download.saveAs(path.join(report, 'digital-human-open-api.pdf'))
  24. assert.equal(fs.readFileSync(path.join(report, 'digital-human-open-api.pdf')).subarray(0, 5).toString(), '%PDF-')
  25. await expect(button).toBeEnabled()
  26. await page.screenshot({ path: path.join(report, '01-pdf-download.png'), animations: 'disabled' })
  27. await page.route('**/open-api/v1/documentation.pdf', route => route.fulfill({ status: 503, contentType: 'application/json', body: JSON.stringify({ code: 50000, message: '导出服务暂不可用', data: null }) }))
  28. await button.click()
  29. await expect(page.locator('.el-message--error')).toBeVisible()
  30. await expect(button).toBeEnabled()
  31. await page.unroute('**/open-api/v1/documentation.pdf')
  32. const retry = page.waitForEvent('download')
  33. await button.click()
  34. assert.equal((await retry).suggestedFilename(), 'digital-human-open-api.pdf')
  35. await page.locator('#endpoint-9').evaluate(el => window.scrollTo({ top: window.scrollY + el.getBoundingClientRect().top - 20, behavior: 'instant' }))
  36. await expect(page.locator('.docs-nav a.active')).toHaveAttribute('href', '#endpoint-9')
  37. assert.deepEqual(errors, [])
  38. fs.writeFileSync(path.join(report, 'results.json'), JSON.stringify({ passed: true, endpoints: 13, backendPdfDownload: true, errorMessage: true, retry: true, scrollSync: true, scriptErrors: errors }, null, 2))
  39. console.log('PDF download, error message, retry and scroll sync passed')
  40. } finally { await browser.close() }