import { expect, test } from './index' import { z } from 'zod' test('scrapes top 3 stories from Hacker News', async ({ page, scraper }) => { await page.goto('https://news.ycombinator.com') const schema = z.object({ top: z .array( z.object({ title: z.string(), }) ) .length(3) .describe('Top 3 stories on Hacker News'), }) // Generate scraping code const { code } = await scraper.generate(page, schema) // Evaluate the generated code in the page context const result: z.infer = await page.evaluate(code) // Validate the result expect(schema.safeParse(result).success).toBe(true) })