Playwright的wait funtion测试

Playwright的wait funtion测试

强制等待

javascript 复制代码
/**
 * Selects an option from a PrimeFaces/JSF dropdown menu.
 * @param {*} page 
 * @param {*} locator 
 * @param {*} option 
 * @param {*} timeout 
 */
const selectDropDown = async (page, locator, option, timeout = 500) => {
  await page.locator(locator).click();
  await page.waitForTimeout(timeout);
  await page.getByRole('option', { name: option }).click();
  await page.waitForTimeout(timeout);
}

等待元素加载

javascript 复制代码
/**
 * Selects an option from a PrimeFaces/JSF dropdown menu.
 * @param {*} page 
 * @param {*} locator 
 * @param {*} option 
 * @param {*} timeout 
 */
const selectDropDown = async (page, locator, option, timeout = 500) => {
  // 1. Click the dropdown trigger
  await page.locator(locator).click();

  // 2. Wait for the option text to be visible anywhere on the page
  // This is robust for PrimeFaces where options are often divs/li with text content
  const optionLocator = page.getByText(option, { exact: true }).first();
  
  // Wait up to 5 seconds for the option to appear
  await expect(optionLocator).toBeVisible({ timeout: 5000 });

  // 3. Click the option
  await optionLocator.click();
}
相关推荐
西洼工作室2 小时前
个人开发者接入阿里云号码认证服务AliCloud-NirvanaPns实现一键登录
python·阿里云·uni-app·全栈·认证授权
星栈9 小时前
CQRS 双库架构:给事件存储单独开一个数据库,到底值不值?
数据库·全栈
老王以为1 天前
Claude Code 从 GUI 到 TUI:开发者界面的范式回归
前端·人工智能·全栈
Bolt3 天前
Codex CLI + 国产模型:一个零侵入的 AI 网关实践
人工智能·全栈
西洼工作室3 天前
fetch+ReadableStream实现SSE推送实时踢人下线
前端·python·全栈
前端再部署3 天前
Nuxt3 AI Agent 控制台实战 03:把 Nuxt3 项目打成 Docker 镜像并部署到 K3S
全栈
漓漾li4 天前
每日面试题-Go全栈AI agent
go·agent·全栈
当时只道寻常5 天前
从零到一打造企业级全栈后台管理系统 —— 技术选型、工程化实践与深度思考
前端·全栈·前端工程化
libokaifa6 天前
Claude Code 工程化落地:被低估的 Hook 机制
aigc·ai编程·全栈