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();
}
相关推荐
烬羽11 小时前
navigator.gpu 存在就够了?WebGPU 检测的两层陷阱
typescript·浏览器·全栈
Hamm1 天前
前端转Java+AI全栈?那我推荐几个实战开源项目给你
前端·后端·全栈
三雒2 天前
拆解 Codex:一个桌面 Agent 到底由哪些核心部分组成?
agent·全栈
烬羽2 天前
《memo 明明加了,为什么子组件还是渲染了?》
react.js·性能优化·全栈
人间凡尔赛2 天前
2026 前端全栈新范式:Server Actions + Edge Runtime,告别传统 API 路由
前端·全栈·next.js
GitLqr3 天前
Flutter 居然能直接跑在 Apple Watch 上了?玩转 flutter-watchos
flutter·全栈·apple watch
GitLqr3 天前
玩转 Flutter 项目依赖:从 pubspec.yaml 到实战包管理
flutter·面试·全栈
烬羽4 天前
useContext 用是用了,但你真的用对了吗?——把 Context 封装进自定义 Hook
前端·react.js·全栈
万敏4 天前
Vue3 全栈实战第五周:Vitest 单元测试从零搭建实战记录
vue.js·node.js·全栈
比特与诗4 天前
MySQL 如何实现 ACID
全栈