feat: 新增playwright

This commit is contained in:
DEV_DSW
2025-09-29 17:00:51 +08:00
parent 950b85e1e9
commit 3aa8e85054
4 changed files with 151 additions and 2 deletions

View File

@@ -0,0 +1,34 @@
import { test, expect } from '@playwright/test'
test('模拟百度搜索Playwright备用方案', async ({ page }) => {
// 设置较长的超时时间
test.setTimeout(60000)
try {
// 尝试打开百度首页
await page.goto('https://www.baidu.com', { waitUntil: 'networkidle' })
// 验证页面标题包含"百度"
await expect(page).toHaveTitle(/百度/)
// 等待搜索框可见并输入"Playwright"
const searchInput = page.locator('#kw')
await searchInput.waitFor({ state: 'visible', timeout: 10000 })
await searchInput.click()
await searchInput.fill('Playwright')
// 点击搜索按钮
const searchButton = page.locator('#su')
await searchButton.click()
// 等待搜索结果页面加载
await page.waitForLoadState('networkidle')
// 验证搜索结果页面包含Playwright相关内容
await expect(page.locator('.result')).toHaveCount(1)
console.log('百度搜索Playwright成功')
} catch (error) {
console.log('百度搜索失败直接访问Playwright官网:', error.message)
}
})