一个基于 Puppeteer 的网页测试工具,使用 Vitest 进行测试。
pnpm install
pnpm test
pnpm test:coverage
pnpm test:ui
用于获取网页HTML内容的函数,支持:
import { fetchHtml } from './src/function/fetchHtml.js'
const result = await fetchHtml({
url: 'https://example.com',
headers: { 'User-Agent': 'Custom Agent' },
queryParams: { page: '1', limit: '10' }
})
console.log(result)
// {
// state: true,
// message: '请求成功',
// data: '<html>...</html>'
// }
提供安全的Puppeteer操作执行器:
import { executeSafePuppeteerOperations, PuppeteerOperations } from './src/function/puppeteer.js'
const operations = [
PuppeteerOperations.navigateToUrl('https://example.com'),
PuppeteerOperations.clickElement('#button'),
PuppeteerOperations.typeText('#input', 'test text')
]
const result = await executeSafePuppeteerOperations(operations)
console.log(result)
当前测试覆盖率:
pnpm dev
pnpm build
pnpm start