[Feature]: Implement hasAttribute(String)
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- java
- Domain
- testing-qa
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.
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.
- Dominant language
- Java
- Stars
- 1.6k
- Forks
- 298
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 14
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.
More from microsoft/playwright-java
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
microsoft/playwright-java#1963 · 1 comment ·
-
P3-collecting-feedback
Difficulty 5/5 Over a week Newbie friendliness 30/100
microsoft/playwright-java#1885 · 3 comments · 4 reactions ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
microsoft/playwright-java#1881 · 3 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
microsoft/playwright-java#1876 · 1 comment ·
-
P3-collecting-feedback
Difficulty 3/5 1-2 days Newbie friendliness 48/100
microsoft/playwright-java#1875 ·
All issues in microsoft/playwright-java
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
objectionary/hone-maven-plugin#1061 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
spring-projects/spring-modulith#1895 ·