[Feature]: Implement hasAttribute(String)

未关闭
#1,844 3 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
java
领域
testing-qa

调研方向

从 issue 中显示的 Java assertion 入口 PlaywrightAssertions.assertThat 开始,并检查现有的 hasAttribute 重载。确认 locator 属性不存在时的表示方式,并添加所请求的仅接收 String 的形式,以便无需值即可断言属性存在或不存在;完成的标准是 API 支持所示的 .not().hasAttribute("min") 用法。

由索引模型根据 Issue 内容生成。

描述

P3-collecting-feedback
🚀 Feature Request

I want to check if a locator has an attribute.
I think that's what toHaveAttribute(name) is doing in typescript.

I tried to:
assertThat(getInputLocator()).not().hasAttribute("min", ""); // that will forbid empty min but not a filled value
or
assertThat(getInputLocator()).not().hasAttribute("min", Pattern.compile(".*"));

And the result is:

  • unexpected value "undefined"

With a new API hasAttribute(String attributeName), I would be able to do:
assertThat(getInputLocator()).not().hasAttribute("min");

That will test if there is an attribute min.

Example
import com.microsoft.playwright.assertions.PlaywrightAssertions;
import java.util.regex.Pattern;

Locator el = page.locator("#my-el");

// Assert the attribute is NOT present:
PlaywrightAssertions.assertThat(el)
    .not()
    .hasAttribute("min", Pattern.compile(".*"));
Motivation

The only workaround I found is to get the attribute and asserts it's null. But it's not the good practice.

Having that will help to check to the absence of a attribute.

主要语言
Java
星标
1.6k
派生
298
平均合并
3 天 2 小时
30 天内合并 PR
14

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/playwright-java 的其他 Issue

查看 microsoft/playwright-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。