Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

35 linhas
2.2 KiB

  1. import { chromium } from '@playwright/test'
  2. import fs from 'node:fs'
  3. import path from 'node:path'
  4. import { pathToFileURL, fileURLToPath } from 'node:url'
  5. const root = path.resolve('reports/review-20260905')
  6. const browser = await chromium.launch()
  7. try {
  8. const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } })
  9. await page.goto(pathToFileURL(path.join(root, 'index.html')).href)
  10. await page.locator('img').evaluateAll(elements => elements.forEach(image => image.loading = 'eager'))
  11. await page.waitForFunction(() => Array.from(document.images).every(image => image.complete))
  12. const imageState = await page.locator('img').evaluateAll(elements => elements.map(image => ({ source: image.getAttribute('src'), width: image.naturalWidth, height: image.naturalHeight })))
  13. if (imageState.some(image => !image.width)) throw new Error('Report has missing images')
  14. const links = await page.locator('a[href]').evaluateAll(elements => elements.map(element => element.href))
  15. for (const link of links) {
  16. if (!link.startsWith('file:')) continue
  17. const url = new URL(link)
  18. url.hash = ''
  19. if (!fs.existsSync(fileURLToPath(url))) throw new Error(`Missing report link: ${url.pathname}`)
  20. }
  21. fs.mkdirSync(path.join(root, 'report-qa'), { recursive: true })
  22. await page.screenshot({ path: path.join(root, 'report-qa/01-report-overview.png') })
  23. await page.getByRole('heading', { name: '5. 截图证据', exact: true }).scrollIntoViewIfNeeded()
  24. await page.screenshot({ path: path.join(root, 'report-qa/02-screenshot-gallery.png') })
  25. await page.getByRole('heading', { name: '7. 待你确认的功能差异与素材选择', exact: true }).scrollIntoViewIfNeeded()
  26. await page.screenshot({ path: path.join(root, 'report-qa/03-confirmation-items.png') })
  27. const result = { imageCount: imageState.length, localLinksChecked: links.filter(link => link.startsWith('file:')).length, documentWidth: await page.evaluate(() => document.documentElement.scrollWidth), viewportWidth: 1440 }
  28. if (result.documentWidth > 1440) throw new Error('Report overflows its viewport')
  29. fs.writeFileSync(path.join(root, 'report-qa/verification.json'), JSON.stringify(result, null, 2))
  30. console.log(JSON.stringify(result))
  31. } finally {
  32. await browser.close()
  33. }