feat: 新增playwright
This commit is contained in:
34
tests/baidu-search-playwright.spec.ts
Normal file
34
tests/baidu-search-playwright.spec.ts
Normal 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)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user