microsoft / microsoft/playwright-java
[Feature]: Implement hasAttribute(String)
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Java
- Sterne
- 1.6k
- Forks
- 298
- Ø Merge
- 3 T. 2 Std.
- Gemergte PRs (30 T.)
- 14
Beschreibung
🚀 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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie beim im Issue gezeigten Java-Assertion-Einstiegspunkt PlaywrightAssertions.assertThat und untersuchen Sie die vorhandenen hasAttribute-Überladungen. Bestätigen Sie, wie das Fehlen eines Locator-Attributs dargestellt wird, und fügen Sie die angeforderte Form hinzu, die nur String verwendet, sodass das Vorhandensein und das Fehlen ohne Wert geprüft werden können; abgeschlossen bedeutet, dass die API die gezeigte Verwendung von .not().hasAttribute("min") unterstützt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- Bereich
- testing-qa
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100