diff --git a/playwright/src/main/java/com/microsoft/playwright/assertions/LocatorAssertions.java b/playwright/src/main/java/com/microsoft/playwright/assertions/LocatorAssertions.java index 780b87751..2c4db2a5b 100644 --- a/playwright/src/main/java/com/microsoft/playwright/assertions/LocatorAssertions.java +++ b/playwright/src/main/java/com/microsoft/playwright/assertions/LocatorAssertions.java @@ -1565,6 +1565,36 @@ default void hasAttribute(String name, Pattern value) { * @since v1.20 */ void hasAttribute(String name, Pattern value, HasAttributeOptions options); + /** + * Ensures the {@code Locator} points to an element with given attribute. When only the attribute name is provided, the + * method asserts attribute presence. + * + *
Usage + *
{@code
+ * assertThat(page.locator("input")).hasAttribute("disabled");
+ * assertThat(page.locator("input")).not().hasAttribute("open");
+ * }
+ *
+ * @param name Attribute name.
+ * @since v1.62
+ */
+ default void hasAttribute(String name) {
+ hasAttribute(name, (HasAttributeOptions) null);
+ }
+ /**
+ * Ensures the {@code Locator} points to an element with given attribute. When only the attribute name is provided, the
+ * method asserts attribute presence.
+ *
+ * Usage + *
{@code
+ * assertThat(page.locator("input")).hasAttribute("disabled");
+ * assertThat(page.locator("input")).not().hasAttribute("open");
+ * }
+ *
+ * @param name Attribute name.
+ * @since v1.62
+ */
+ void hasAttribute(String name, HasAttributeOptions options);
/**
* Ensures the {@code Locator} points to an element with given CSS classes. When a string is provided, it must fully match
* the element's {@code class} attribute. To match individual classes use {@link
diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/LocatorAssertionsImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/LocatorAssertionsImpl.java
index 088910c98..4e107d00a 100644
--- a/playwright/src/main/java/com/microsoft/playwright/impl/LocatorAssertionsImpl.java
+++ b/playwright/src/main/java/com/microsoft/playwright/impl/LocatorAssertionsImpl.java
@@ -190,6 +190,18 @@ private void hasAttribute(String name, ExpectedTextValue expectedText, Object ex
expectImpl("to.have.attribute.value", expectedText, expectedValue, message, commonOptions, "Assert \"hasAttribute\"");
}
+ @Override
+ public void hasAttribute(String name, HasAttributeOptions options) {
+ if (options == null) {
+ options = new HasAttributeOptions();
+ }
+ FrameExpectOptions commonOptions = convertType(options, FrameExpectOptions.class);
+ commonOptions.expressionArg = name;
+ String message = "Locator expected to have attribute '" + name + "'";
+ List