import { test, expect } from '@playwright/test'; test.describe('示例提示词轮播', () => { test('每隔几秒自动切换', async ({ page }) => { await page.goto('http://localhost:5173/#/pages/book-generator/create', { waitUntil: 'networkidle' }); await page.waitForSelector('.example-chip', { timeout: 10000 }); const initial = (await page.locator('.example-chip').first().textContent())?.trim() || ''; console.log('[T=0] 示例:', initial); expect(initial.length).toBeGreaterThan(0); await page.waitForTimeout(5500); const after5s = (await page.locator('.example-chip').first().textContent())?.trim() || ''; console.log('[T=5s] 示例:', after5s); expect(after5s).not.toBe(initial); await page.waitForTimeout(5000); const after10s = (await page.locator('.example-chip').first().textContent())?.trim() || ''; console.log('[T=10s]示例:', after10s); expect(after10s).not.toBe(after5s); await page.screenshot({ path: 'tests/example-rotation.png', fullPage: false }); }); test('点击示例填充到文本框', async ({ page }) => { await page.goto('http://localhost:5173/#/pages/book-generator/create', { waitUntil: 'networkidle' }); await page.waitForSelector('.example-chip', { timeout: 10000 }); const text = (await page.locator('.example-chip .example-chip-text').first().textContent())?.trim() || ''; await page.locator('.example-chip').first().click(); await page.waitForTimeout(500); const value = await page.locator('textarea.uni-textarea-textarea').first().evaluate((el: any) => el.value); console.log('点击后文本框内容:', value); expect(value).toBe(text); }); test('页面只展示一个示例 chip(不重复铺开)', async ({ page }) => { await page.goto('http://localhost:5173/#/pages/book-generator/create', { waitUntil: 'networkidle' }); await page.waitForSelector('.example-chip', { timeout: 10000 }); const count = await page.locator('.example-chip').count(); console.log('chip 数量:', count); expect(count).toBe(1); }); });