Skip to content

[Feature]: Implement hasAttribute(String)#1844

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions