microsoft / microsoft/playwright-java
[Feature]: Implement hasAttribute(String)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.6k
- Forks
- 298
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 14
Description
🚀 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Java assertion entry point shown in the issue, PlaywrightAssertions.assertThat, and inspect the existing hasAttribute overloads. Confirm how locator attribute absence is represented and add the requested String-only form so presence and absence can be asserted without a value; done means the API supports the shown .not().hasAttribute("min") usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100