You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WebdriverIO元素值断言失效:预期30却判定通过的修复方案

修复方案

你的代码存在两个核心问题导致断言失效:

  1. 未等待异步操作结果:element.getAttribute("value") 返回的是Promise对象,直接用 === 对比时,实际是拿Promise和字符串"3"比较,结果为false。但chai的expect接收非布尔值时会判断其是否为truthy——Promise属于truthy值,因此断言直接通过,完全没起到验证作用。

  2. 预期值错误:你实际需要验证的是"30",但代码里写的是"3"。

修复后的代码示例:

async user_verify_loan_term() {
  const actualValue = await element.getAttribute("value");
  chaiExpect(actualValue).to.equal("30");
}

也可以简化为直接在断言中等待异步结果:

async user_verify_loan_term() {
  chaiExpect(await element.getAttribute("value")).to.equal("30");
}

修改后会先等待获取到元素的真实value值,再和预期的"30"做严格相等校验,就能正常触发断言的失败/通过逻辑了。

内容的提问来源于stack exchange,提问作者Devesh Joshi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 09:11:53