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 天前
零到全栈(网页从哪来,服务器怎么架)
全栈
Ticnix2 天前
42 天 71 次提交之后,我重新看了一遍自己的架构决策
python·agent·全栈
LEE3 天前
前端转型全栈 03:接口失败也返回 200,OpenAPI 契约与错误码怎么定
前端·后端·全栈
SL_staff3 天前
MQTT Topic权限越界:JVS-IOT中系统Topic与自定义Topic的权责边界与验证实践
java·物联网·全栈
SL_staff4 天前
财务系统慎用低代码?从数据模型闭环看合规落地的技术实践
java·低代码·全栈
老王以为4 天前
走进 AI Agent 第四篇(上):知识获取管道——RAG 基础
前端·人工智能·全栈
小星星_20267 天前
16 万行代码是怎么“跑”出来的?
人工智能·全栈
SL_staff8 天前
JVS-Logic:从页面配置工具到企业级业务逻辑中枢的技术演进
java·算法·全栈
万敏8 天前
Vue3 全栈实战第九周:Node.js + Express 后端从零搭建实战记录
vue.js·node.js·全栈
MingQi398 天前
DevFlow Harness 全栈实践 · M1.5:用户体系、多对话与聊天分享
全栈