Interface LocatorAssertions

  • All Known Implementing Classes:
    LocatorAssertionsImpl

    public interface LocatorAssertions
    The LocatorAssertions class provides assertion methods that can be used to make assertions about the Locator state in the tests.
    {@code
     ...
     import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
    
     public class TestLocator {
       ...
    • Method Detail

      • not

        LocatorAssertions not()
        Makes the assertion check for the opposite condition. For example, this code tests that the Locator doesn't contain text "error":
        
         assertThat(locator).not().containsText("error");
         
        Since:
        v1.20
      • isAttached

        default void isAttached()
        Ensures that Locator points to an attached DOM node.

        **Usage**

        
         assertThat(page.getByText("Hidden text")).isAttached();
         
        Since:
        v1.33
      • isChecked

        default void isChecked()
        Ensures the Locator points to a checked input.

        **Usage**

        
         assertThat(page.getByLabel("Subscribe to newsletter")).isChecked();
         
        Since:
        v1.20
      • isChecked

        void isChecked​(LocatorAssertions.IsCheckedOptions options)
        Ensures the Locator points to a checked input.

        **Usage**

        
         assertThat(page.getByLabel("Subscribe to newsletter")).isChecked();
         
        Since:
        v1.20
      • isDisabled

        default void isDisabled()
        Ensures the Locator points to a disabled element. Element is disabled if it has "disabled" attribute or is disabled via 'aria-disabled'. Note that only native control elements such as HTML button, input, select, textarea, option, optgroup can be disabled by setting "disabled" attribute. "disabled" attribute on other elements is ignored by the browser.

        **Usage**

        
         assertThat(page.locator("button.submit")).isDisabled();
         
        Since:
        v1.20
      • isDisabled

        void isDisabled​(LocatorAssertions.IsDisabledOptions options)
        Ensures the Locator points to a disabled element. Element is disabled if it has "disabled" attribute or is disabled via 'aria-disabled'. Note that only native control elements such as HTML button, input, select, textarea, option, optgroup can be disabled by setting "disabled" attribute. "disabled" attribute on other elements is ignored by the browser.

        **Usage**

        
         assertThat(page.locator("button.submit")).isDisabled();
         
        Since:
        v1.20
      • isEditable

        default void isEditable()
        Ensures the Locator points to an editable element.

        **Usage**

        
         assertThat(page.getByRole(AriaRole.TEXTBOX)).isEditable();
         
        Since:
        v1.20
      • isEditable

        void isEditable​(LocatorAssertions.IsEditableOptions options)
        Ensures the Locator points to an editable element.

        **Usage**

        
         assertThat(page.getByRole(AriaRole.TEXTBOX)).isEditable();
         
        Since:
        v1.20
      • isEmpty

        default void isEmpty()
        Ensures the Locator points to an empty editable element or to a DOM node that has no text.

        **Usage**

        
         assertThat(page.locator("div.warning")).isEmpty();
         
        Since:
        v1.20
      • isEmpty

        void isEmpty​(LocatorAssertions.IsEmptyOptions options)
        Ensures the Locator points to an empty editable element or to a DOM node that has no text.

        **Usage**

        
         assertThat(page.locator("div.warning")).isEmpty();
         
        Since:
        v1.20
      • isEnabled

        default void isEnabled()
        Ensures the Locator points to an enabled element.

        **Usage**

        
         assertThat(page.locator("button.submit")).isEnabled();
         
        Since:
        v1.20
      • isEnabled

        void isEnabled​(LocatorAssertions.IsEnabledOptions options)
        Ensures the Locator points to an enabled element.

        **Usage**

        
         assertThat(page.locator("button.submit")).isEnabled();
         
        Since:
        v1.20
      • isFocused

        default void isFocused()
        Ensures the Locator points to a focused DOM node.

        **Usage**

        
         assertThat(page.getByRole(AriaRole.TEXTBOX)).isFocused();
         
        Since:
        v1.20
      • isFocused

        void isFocused​(LocatorAssertions.IsFocusedOptions options)
        Ensures the Locator points to a focused DOM node.

        **Usage**

        
         assertThat(page.getByRole(AriaRole.TEXTBOX)).isFocused();
         
        Since:
        v1.20
      • isHidden

        default void isHidden()
        Ensures that Locator either does not resolve to any DOM node, or resolves to a non-visible one.

        **Usage**

        
         assertThat(page.locator(".my-element")).isHidden();
         
        Since:
        v1.20
      • isHidden

        void isHidden​(LocatorAssertions.IsHiddenOptions options)
        Ensures that Locator either does not resolve to any DOM node, or resolves to a non-visible one.

        **Usage**

        
         assertThat(page.locator(".my-element")).isHidden();
         
        Since:
        v1.20
      • isInViewport

        default void isInViewport()
        Ensures the Locator points to an element that intersects viewport, according to the intersection observer API.

        **Usage**

        
         Locator locator = page.getByRole(AriaRole.BUTTON);
         // Make sure at least some part of element intersects viewport.
         assertThat(locator).isInViewport();
         // Make sure element is fully outside of viewport.
         assertThat(locator).not().isInViewport();
         // Make sure that at least half of the element intersects viewport.
         assertThat(locator).isInViewport(new LocatorAssertions.IsInViewportOptions().setRatio(0.5));
         
        Since:
        v1.31
      • isInViewport

        void isInViewport​(LocatorAssertions.IsInViewportOptions options)
        Ensures the Locator points to an element that intersects viewport, according to the intersection observer API.

        **Usage**

        
         Locator locator = page.getByRole(AriaRole.BUTTON);
         // Make sure at least some part of element intersects viewport.
         assertThat(locator).isInViewport();
         // Make sure element is fully outside of viewport.
         assertThat(locator).not().isInViewport();
         // Make sure that at least half of the element intersects viewport.
         assertThat(locator).isInViewport(new LocatorAssertions.IsInViewportOptions().setRatio(0.5));
         
        Since:
        v1.31
      • isVisible

        default void isVisible()
        Ensures that Locator points to an attached and visible DOM node.

        To check that at least one element from the list is visible, use Locator.first().

        **Usage**

        
         // A specific element is visible.
         assertThat(page.getByText("Welcome")).isVisible();
        
         // At least one item in the list is visible.
         asserThat(page.getByTestId("todo-item").first()).isVisible();
        
         // At least one of the two elements is visible, possibly both.
         asserThat(
           page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign in"))
             .or(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign up")))
             .first()
         ).isVisible();
         
        Since:
        v1.20
      • isVisible

        void isVisible​(LocatorAssertions.IsVisibleOptions options)
        Ensures that Locator points to an attached and visible DOM node.

        To check that at least one element from the list is visible, use Locator.first().

        **Usage**

        
         // A specific element is visible.
         assertThat(page.getByText("Welcome")).isVisible();
        
         // At least one item in the list is visible.
         asserThat(page.getByTestId("todo-item").first()).isVisible();
        
         // At least one of the two elements is visible, possibly both.
         asserThat(
           page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign in"))
             .or(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign up")))
             .first()
         ).isVisible();
         
        Since:
        v1.20
      • containsText

        default void containsText​(java.lang.String expected)
        Ensures the Locator points to an element that contains the given text. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator(".title")).containsText("substring");
         

        If you pass an array as an expected value, the expectations are:

        1. Locator resolves to a list of elements.
        2. Elements from a **subset** of this list contain text from the expected array, respectively.
        3. The matching subset of elements has the same order as the expected array.
        4. Each text value from the expected array is matched by some element from the list.

        For example, consider the following list:

        Let's see how we can use the assertion:

        
         // ✓ Contains the right items in the right order
         assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3", "Text 4"});
        
         // ✖ Wrong order
         assertThat(page.locator("ul > li")).containsText(new String[] {"Text 3", "Text 2"});
        
         // ✖ No item contains this text
         assertThat(page.locator("ul > li")).containsText(new String[] {"Some 33"});
        
         // ✖ Locator points to the outer list element, not to the list items
         assertThat(page.locator("ul")).containsText(new String[] {"Text 3"});
         
        Parameters:
        expected - Expected substring or RegExp or a list of those.
        Since:
        v1.20
      • containsText

        void containsText​(java.lang.String expected,
                          LocatorAssertions.ContainsTextOptions options)
        Ensures the Locator points to an element that contains the given text. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator(".title")).containsText("substring");
         

        If you pass an array as an expected value, the expectations are:

        1. Locator resolves to a list of elements.
        2. Elements from a **subset** of this list contain text from the expected array, respectively.
        3. The matching subset of elements has the same order as the expected array.
        4. Each text value from the expected array is matched by some element from the list.

        For example, consider the following list:

        Let's see how we can use the assertion:

        
         // ✓ Contains the right items in the right order
         assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3", "Text 4"});
        
         // ✖ Wrong order
         assertThat(page.locator("ul > li")).containsText(new String[] {"Text 3", "Text 2"});
        
         // ✖ No item contains this text
         assertThat(page.locator("ul > li")).containsText(new String[] {"Some 33"});
        
         // ✖ Locator points to the outer list element, not to the list items
         assertThat(page.locator("ul")).containsText(new String[] {"Text 3"});
         
        Parameters:
        expected - Expected substring or RegExp or a list of those.
        Since:
        v1.20
      • containsText

        default void containsText​(java.util.regex.Pattern expected)
        Ensures the Locator points to an element that contains the given text. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator(".title")).containsText("substring");
         

        If you pass an array as an expected value, the expectations are:

        1. Locator resolves to a list of elements.
        2. Elements from a **subset** of this list contain text from the expected array, respectively.
        3. The matching subset of elements has the same order as the expected array.
        4. Each text value from the expected array is matched by some element from the list.

        For example, consider the following list:

        Let's see how we can use the assertion:

        
         // ✓ Contains the right items in the right order
         assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3", "Text 4"});
        
         // ✖ Wrong order
         assertThat(page.locator("ul > li")).containsText(new String[] {"Text 3", "Text 2"});
        
         // ✖ No item contains this text
         assertThat(page.locator("ul > li")).containsText(new String[] {"Some 33"});
        
         // ✖ Locator points to the outer list element, not to the list items
         assertThat(page.locator("ul")).containsText(new String[] {"Text 3"});
         
        Parameters:
        expected - Expected substring or RegExp or a list of those.
        Since:
        v1.20
      • containsText

        void containsText​(java.util.regex.Pattern expected,
                          LocatorAssertions.ContainsTextOptions options)
        Ensures the Locator points to an element that contains the given text. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator(".title")).containsText("substring");
         

        If you pass an array as an expected value, the expectations are:

        1. Locator resolves to a list of elements.
        2. Elements from a **subset** of this list contain text from the expected array, respectively.
        3. The matching subset of elements has the same order as the expected array.
        4. Each text value from the expected array is matched by some element from the list.

        For example, consider the following list:

        Let's see how we can use the assertion:

        
         // ✓ Contains the right items in the right order
         assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3", "Text 4"});
        
         // ✖ Wrong order
         assertThat(page.locator("ul > li")).containsText(new String[] {"Text 3", "Text 2"});
        
         // ✖ No item contains this text
         assertThat(page.locator("ul > li")).containsText(new String[] {"Some 33"});
        
         // ✖ Locator points to the outer list element, not to the list items
         assertThat(page.locator("ul")).containsText(new String[] {"Text 3"});
         
        Parameters:
        expected - Expected substring or RegExp or a list of those.
        Since:
        v1.20
      • containsText

        default void containsText​(java.lang.String[] expected)
        Ensures the Locator points to an element that contains the given text. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator(".title")).containsText("substring");
         

        If you pass an array as an expected value, the expectations are:

        1. Locator resolves to a list of elements.
        2. Elements from a **subset** of this list contain text from the expected array, respectively.
        3. The matching subset of elements has the same order as the expected array.
        4. Each text value from the expected array is matched by some element from the list.

        For example, consider the following list:

        Let's see how we can use the assertion:

        
         // ✓ Contains the right items in the right order
         assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3", "Text 4"});
        
         // ✖ Wrong order
         assertThat(page.locator("ul > li")).containsText(new String[] {"Text 3", "Text 2"});
        
         // ✖ No item contains this text
         assertThat(page.locator("ul > li")).containsText(new String[] {"Some 33"});
        
         // ✖ Locator points to the outer list element, not to the list items
         assertThat(page.locator("ul")).containsText(new String[] {"Text 3"});
         
        Parameters:
        expected - Expected substring or RegExp or a list of those.
        Since:
        v1.20
      • containsText

        void containsText​(java.lang.String[] expected,
                          LocatorAssertions.ContainsTextOptions options)
        Ensures the Locator points to an element that contains the given text. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator(".title")).containsText("substring");
         

        If you pass an array as an expected value, the expectations are:

        1. Locator resolves to a list of elements.
        2. Elements from a **subset** of this list contain text from the expected array, respectively.
        3. The matching subset of elements has the same order as the expected array.
        4. Each text value from the expected array is matched by some element from the list.

        For example, consider the following list:

        Let's see how we can use the assertion:

        
         // ✓ Contains the right items in the right order
         assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3", "Text 4"});
        
         // ✖ Wrong order
         assertThat(page.locator("ul > li")).containsText(new String[] {"Text 3", "Text 2"});
        
         // ✖ No item contains this text
         assertThat(page.locator("ul > li")).containsText(new String[] {"Some 33"});
        
         // ✖ Locator points to the outer list element, not to the list items
         assertThat(page.locator("ul")).containsText(new String[] {"Text 3"});
         
        Parameters:
        expected - Expected substring or RegExp or a list of those.
        Since:
        v1.20
      • containsText

        default void containsText​(java.util.regex.Pattern[] expected)
        Ensures the Locator points to an element that contains the given text. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator(".title")).containsText("substring");
         

        If you pass an array as an expected value, the expectations are:

        1. Locator resolves to a list of elements.
        2. Elements from a **subset** of this list contain text from the expected array, respectively.
        3. The matching subset of elements has the same order as the expected array.
        4. Each text value from the expected array is matched by some element from the list.

        For example, consider the following list:

        Let's see how we can use the assertion:

        
         // ✓ Contains the right items in the right order
         assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3", "Text 4"});
        
         // ✖ Wrong order
         assertThat(page.locator("ul > li")).containsText(new String[] {"Text 3", "Text 2"});
        
         // ✖ No item contains this text
         assertThat(page.locator("ul > li")).containsText(new String[] {"Some 33"});
        
         // ✖ Locator points to the outer list element, not to the list items
         assertThat(page.locator("ul")).containsText(new String[] {"Text 3"});
         
        Parameters:
        expected - Expected substring or RegExp or a list of those.
        Since:
        v1.20
      • containsText

        void containsText​(java.util.regex.Pattern[] expected,
                          LocatorAssertions.ContainsTextOptions options)
        Ensures the Locator points to an element that contains the given text. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator(".title")).containsText("substring");
         

        If you pass an array as an expected value, the expectations are:

        1. Locator resolves to a list of elements.
        2. Elements from a **subset** of this list contain text from the expected array, respectively.
        3. The matching subset of elements has the same order as the expected array.
        4. Each text value from the expected array is matched by some element from the list.

        For example, consider the following list:

        Let's see how we can use the assertion:

        
         // ✓ Contains the right items in the right order
         assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3", "Text 4"});
        
         // ✖ Wrong order
         assertThat(page.locator("ul > li")).containsText(new String[] {"Text 3", "Text 2"});
        
         // ✖ No item contains this text
         assertThat(page.locator("ul > li")).containsText(new String[] {"Some 33"});
        
         // ✖ Locator points to the outer list element, not to the list items
         assertThat(page.locator("ul")).containsText(new String[] {"Text 3"});
         
        Parameters:
        expected - Expected substring or RegExp or a list of those.
        Since:
        v1.20
      • hasAttribute

        default void hasAttribute​(java.lang.String name,
                                  java.lang.String value)
        Ensures the Locator points to an element with given attribute.

        **Usage**

        
         assertThat(page.locator("input")).hasAttribute("type", "text");
         
        Parameters:
        name - Attribute name.
        value - Expected attribute value.
        Since:
        v1.20
      • hasAttribute

        void hasAttribute​(java.lang.String name,
                          java.lang.String value,
                          LocatorAssertions.HasAttributeOptions options)
        Ensures the Locator points to an element with given attribute.

        **Usage**

        
         assertThat(page.locator("input")).hasAttribute("type", "text");
         
        Parameters:
        name - Attribute name.
        value - Expected attribute value.
        Since:
        v1.20
      • hasAttribute

        default void hasAttribute​(java.lang.String name,
                                  java.util.regex.Pattern value)
        Ensures the Locator points to an element with given attribute.

        **Usage**

        
         assertThat(page.locator("input")).hasAttribute("type", "text");
         
        Parameters:
        name - Attribute name.
        value - Expected attribute value.
        Since:
        v1.20
      • hasAttribute

        void hasAttribute​(java.lang.String name,
                          java.util.regex.Pattern value,
                          LocatorAssertions.HasAttributeOptions options)
        Ensures the Locator points to an element with given attribute.

        **Usage**

        
         assertThat(page.locator("input")).hasAttribute("type", "text");
         
        Parameters:
        name - Attribute name.
        value - Expected attribute value.
        Since:
        v1.20
      • hasClass

        default void hasClass​(java.lang.String expected)
        Ensures the Locator points to an element with given CSS classes. This needs to be a full match or using a relaxed regular expression.

        **Usage**

        
         assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
         assertThat(page.locator("#component")).hasClass("selected row");
         

        Note that if array is passed as an expected value, entire lists of elements can be asserted:

        
         assertThat(page.locator("list > .component")).hasClass(new String[] {"component", "component selected", "component"});
         
        Parameters:
        expected - Expected class or RegExp or a list of those.
        Since:
        v1.20
      • hasClass

        void hasClass​(java.lang.String expected,
                      LocatorAssertions.HasClassOptions options)
        Ensures the Locator points to an element with given CSS classes. This needs to be a full match or using a relaxed regular expression.

        **Usage**

        
         assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
         assertThat(page.locator("#component")).hasClass("selected row");
         

        Note that if array is passed as an expected value, entire lists of elements can be asserted:

        
         assertThat(page.locator("list > .component")).hasClass(new String[] {"component", "component selected", "component"});
         
        Parameters:
        expected - Expected class or RegExp or a list of those.
        Since:
        v1.20
      • hasClass

        default void hasClass​(java.util.regex.Pattern expected)
        Ensures the Locator points to an element with given CSS classes. This needs to be a full match or using a relaxed regular expression.

        **Usage**

        
         assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
         assertThat(page.locator("#component")).hasClass("selected row");
         

        Note that if array is passed as an expected value, entire lists of elements can be asserted:

        
         assertThat(page.locator("list > .component")).hasClass(new String[] {"component", "component selected", "component"});
         
        Parameters:
        expected - Expected class or RegExp or a list of those.
        Since:
        v1.20
      • hasClass

        void hasClass​(java.util.regex.Pattern expected,
                      LocatorAssertions.HasClassOptions options)
        Ensures the Locator points to an element with given CSS classes. This needs to be a full match or using a relaxed regular expression.

        **Usage**

        
         assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
         assertThat(page.locator("#component")).hasClass("selected row");
         

        Note that if array is passed as an expected value, entire lists of elements can be asserted:

        
         assertThat(page.locator("list > .component")).hasClass(new String[] {"component", "component selected", "component"});
         
        Parameters:
        expected - Expected class or RegExp or a list of those.
        Since:
        v1.20
      • hasClass

        default void hasClass​(java.lang.String[] expected)
        Ensures the Locator points to an element with given CSS classes. This needs to be a full match or using a relaxed regular expression.

        **Usage**

        
         assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
         assertThat(page.locator("#component")).hasClass("selected row");
         

        Note that if array is passed as an expected value, entire lists of elements can be asserted:

        
         assertThat(page.locator("list > .component")).hasClass(new String[] {"component", "component selected", "component"});
         
        Parameters:
        expected - Expected class or RegExp or a list of those.
        Since:
        v1.20
      • hasClass

        void hasClass​(java.lang.String[] expected,
                      LocatorAssertions.HasClassOptions options)
        Ensures the Locator points to an element with given CSS classes. This needs to be a full match or using a relaxed regular expression.

        **Usage**

        
         assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
         assertThat(page.locator("#component")).hasClass("selected row");
         

        Note that if array is passed as an expected value, entire lists of elements can be asserted:

        
         assertThat(page.locator("list > .component")).hasClass(new String[] {"component", "component selected", "component"});
         
        Parameters:
        expected - Expected class or RegExp or a list of those.
        Since:
        v1.20
      • hasClass

        default void hasClass​(java.util.regex.Pattern[] expected)
        Ensures the Locator points to an element with given CSS classes. This needs to be a full match or using a relaxed regular expression.

        **Usage**

        
         assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
         assertThat(page.locator("#component")).hasClass("selected row");
         

        Note that if array is passed as an expected value, entire lists of elements can be asserted:

        
         assertThat(page.locator("list > .component")).hasClass(new String[] {"component", "component selected", "component"});
         
        Parameters:
        expected - Expected class or RegExp or a list of those.
        Since:
        v1.20
      • hasClass

        void hasClass​(java.util.regex.Pattern[] expected,
                      LocatorAssertions.HasClassOptions options)
        Ensures the Locator points to an element with given CSS classes. This needs to be a full match or using a relaxed regular expression.

        **Usage**

        
         assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
         assertThat(page.locator("#component")).hasClass("selected row");
         

        Note that if array is passed as an expected value, entire lists of elements can be asserted:

        
         assertThat(page.locator("list > .component")).hasClass(new String[] {"component", "component selected", "component"});
         
        Parameters:
        expected - Expected class or RegExp or a list of those.
        Since:
        v1.20
      • hasCount

        default void hasCount​(int count)
        Ensures the Locator resolves to an exact number of DOM nodes.

        **Usage**

        
         assertThat(page.locator("list > .component")).hasCount(3);
         
        Parameters:
        count - Expected count.
        Since:
        v1.20
      • hasCount

        void hasCount​(int count,
                      LocatorAssertions.HasCountOptions options)
        Ensures the Locator resolves to an exact number of DOM nodes.

        **Usage**

        
         assertThat(page.locator("list > .component")).hasCount(3);
         
        Parameters:
        count - Expected count.
        Since:
        v1.20
      • hasCSS

        default void hasCSS​(java.lang.String name,
                            java.lang.String value)
        Ensures the Locator resolves to an element with the given computed CSS style.

        **Usage**

        
         assertThat(page.getByRole(AriaRole.BUTTON)).hasCSS("display", "flex");
         
        Parameters:
        name - CSS property name.
        value - CSS property value.
        Since:
        v1.20
      • hasCSS

        void hasCSS​(java.lang.String name,
                    java.lang.String value,
                    LocatorAssertions.HasCSSOptions options)
        Ensures the Locator resolves to an element with the given computed CSS style.

        **Usage**

        
         assertThat(page.getByRole(AriaRole.BUTTON)).hasCSS("display", "flex");
         
        Parameters:
        name - CSS property name.
        value - CSS property value.
        Since:
        v1.20
      • hasCSS

        default void hasCSS​(java.lang.String name,
                            java.util.regex.Pattern value)
        Ensures the Locator resolves to an element with the given computed CSS style.

        **Usage**

        
         assertThat(page.getByRole(AriaRole.BUTTON)).hasCSS("display", "flex");
         
        Parameters:
        name - CSS property name.
        value - CSS property value.
        Since:
        v1.20
      • hasCSS

        void hasCSS​(java.lang.String name,
                    java.util.regex.Pattern value,
                    LocatorAssertions.HasCSSOptions options)
        Ensures the Locator resolves to an element with the given computed CSS style.

        **Usage**

        
         assertThat(page.getByRole(AriaRole.BUTTON)).hasCSS("display", "flex");
         
        Parameters:
        name - CSS property name.
        value - CSS property value.
        Since:
        v1.20
      • hasId

        default void hasId​(java.lang.String id)
        Ensures the Locator points to an element with the given DOM Node ID.

        **Usage**

        
         assertThat(page.getByRole(AriaRole.TEXTBOX)).hasId("lastname");
         
        Parameters:
        id - Element id.
        Since:
        v1.20
      • hasId

        void hasId​(java.lang.String id,
                   LocatorAssertions.HasIdOptions options)
        Ensures the Locator points to an element with the given DOM Node ID.

        **Usage**

        
         assertThat(page.getByRole(AriaRole.TEXTBOX)).hasId("lastname");
         
        Parameters:
        id - Element id.
        Since:
        v1.20
      • hasId

        default void hasId​(java.util.regex.Pattern id)
        Ensures the Locator points to an element with the given DOM Node ID.

        **Usage**

        
         assertThat(page.getByRole(AriaRole.TEXTBOX)).hasId("lastname");
         
        Parameters:
        id - Element id.
        Since:
        v1.20
      • hasId

        void hasId​(java.util.regex.Pattern id,
                   LocatorAssertions.HasIdOptions options)
        Ensures the Locator points to an element with the given DOM Node ID.

        **Usage**

        
         assertThat(page.getByRole(AriaRole.TEXTBOX)).hasId("lastname");
         
        Parameters:
        id - Element id.
        Since:
        v1.20
      • hasJSProperty

        default void hasJSProperty​(java.lang.String name,
                                   java.lang.Object value)
        Ensures the Locator points to an element with given JavaScript property. Note that this property can be of a primitive type as well as a plain serializable JavaScript object.

        **Usage**

        
         assertThat(page.locator("input")).hasJSProperty("loaded", true);
         
        Parameters:
        name - Property name.
        value - Property value.
        Since:
        v1.20
      • hasJSProperty

        void hasJSProperty​(java.lang.String name,
                           java.lang.Object value,
                           LocatorAssertions.HasJSPropertyOptions options)
        Ensures the Locator points to an element with given JavaScript property. Note that this property can be of a primitive type as well as a plain serializable JavaScript object.

        **Usage**

        
         assertThat(page.locator("input")).hasJSProperty("loaded", true);
         
        Parameters:
        name - Property name.
        value - Property value.
        Since:
        v1.20
      • hasText

        default void hasText​(java.lang.String expected)
        Ensures the Locator points to an element with the given text. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator(".title")).hasText("Welcome, Test User");
         assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
         

        If you pass an array as an expected value, the expectations are:

        1. Locator resolves to a list of elements.
        2. The number of elements equals the number of expected values in the array.
        3. Elements from the list have text matching expected array values, one by one, in order.

        For example, consider the following list:

        Let's see how we can use the assertion:

        
         // ✓ Has the right items in the right order
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
        
         // ✖ Wrong order
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 3", "Text 2", "Text 1"});
        
         // ✖ Last item does not match
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text"});
        
         // ✖ Locator points to the outer list element, not to the list items
         assertThat(page.locator("ul")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
         
        Parameters:
        expected - Expected string or RegExp or a list of those.
        Since:
        v1.20
      • hasText

        void hasText​(java.lang.String expected,
                     LocatorAssertions.HasTextOptions options)
        Ensures the Locator points to an element with the given text. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator(".title")).hasText("Welcome, Test User");
         assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
         

        If you pass an array as an expected value, the expectations are:

        1. Locator resolves to a list of elements.
        2. The number of elements equals the number of expected values in the array.
        3. Elements from the list have text matching expected array values, one by one, in order.

        For example, consider the following list:

        Let's see how we can use the assertion:

        
         // ✓ Has the right items in the right order
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
        
         // ✖ Wrong order
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 3", "Text 2", "Text 1"});
        
         // ✖ Last item does not match
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text"});
        
         // ✖ Locator points to the outer list element, not to the list items
         assertThat(page.locator("ul")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
         
        Parameters:
        expected - Expected string or RegExp or a list of those.
        Since:
        v1.20
      • hasText

        default void hasText​(java.util.regex.Pattern expected)
        Ensures the Locator points to an element with the given text. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator(".title")).hasText("Welcome, Test User");
         assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
         

        If you pass an array as an expected value, the expectations are:

        1. Locator resolves to a list of elements.
        2. The number of elements equals the number of expected values in the array.
        3. Elements from the list have text matching expected array values, one by one, in order.

        For example, consider the following list:

        Let's see how we can use the assertion:

        
         // ✓ Has the right items in the right order
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
        
         // ✖ Wrong order
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 3", "Text 2", "Text 1"});
        
         // ✖ Last item does not match
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text"});
        
         // ✖ Locator points to the outer list element, not to the list items
         assertThat(page.locator("ul")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
         
        Parameters:
        expected - Expected string or RegExp or a list of those.
        Since:
        v1.20
      • hasText

        void hasText​(java.util.regex.Pattern expected,
                     LocatorAssertions.HasTextOptions options)
        Ensures the Locator points to an element with the given text. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator(".title")).hasText("Welcome, Test User");
         assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
         

        If you pass an array as an expected value, the expectations are:

        1. Locator resolves to a list of elements.
        2. The number of elements equals the number of expected values in the array.
        3. Elements from the list have text matching expected array values, one by one, in order.

        For example, consider the following list:

        Let's see how we can use the assertion:

        
         // ✓ Has the right items in the right order
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
        
         // ✖ Wrong order
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 3", "Text 2", "Text 1"});
        
         // ✖ Last item does not match
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text"});
        
         // ✖ Locator points to the outer list element, not to the list items
         assertThat(page.locator("ul")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
         
        Parameters:
        expected - Expected string or RegExp or a list of those.
        Since:
        v1.20
      • hasText

        default void hasText​(java.lang.String[] expected)
        Ensures the Locator points to an element with the given text. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator(".title")).hasText("Welcome, Test User");
         assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
         

        If you pass an array as an expected value, the expectations are:

        1. Locator resolves to a list of elements.
        2. The number of elements equals the number of expected values in the array.
        3. Elements from the list have text matching expected array values, one by one, in order.

        For example, consider the following list:

        Let's see how we can use the assertion:

        
         // ✓ Has the right items in the right order
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
        
         // ✖ Wrong order
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 3", "Text 2", "Text 1"});
        
         // ✖ Last item does not match
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text"});
        
         // ✖ Locator points to the outer list element, not to the list items
         assertThat(page.locator("ul")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
         
        Parameters:
        expected - Expected string or RegExp or a list of those.
        Since:
        v1.20
      • hasText

        void hasText​(java.lang.String[] expected,
                     LocatorAssertions.HasTextOptions options)
        Ensures the Locator points to an element with the given text. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator(".title")).hasText("Welcome, Test User");
         assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
         

        If you pass an array as an expected value, the expectations are:

        1. Locator resolves to a list of elements.
        2. The number of elements equals the number of expected values in the array.
        3. Elements from the list have text matching expected array values, one by one, in order.

        For example, consider the following list:

        Let's see how we can use the assertion:

        
         // ✓ Has the right items in the right order
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
        
         // ✖ Wrong order
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 3", "Text 2", "Text 1"});
        
         // ✖ Last item does not match
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text"});
        
         // ✖ Locator points to the outer list element, not to the list items
         assertThat(page.locator("ul")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
         
        Parameters:
        expected - Expected string or RegExp or a list of those.
        Since:
        v1.20
      • hasText

        default void hasText​(java.util.regex.Pattern[] expected)
        Ensures the Locator points to an element with the given text. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator(".title")).hasText("Welcome, Test User");
         assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
         

        If you pass an array as an expected value, the expectations are:

        1. Locator resolves to a list of elements.
        2. The number of elements equals the number of expected values in the array.
        3. Elements from the list have text matching expected array values, one by one, in order.

        For example, consider the following list:

        Let's see how we can use the assertion:

        
         // ✓ Has the right items in the right order
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
        
         // ✖ Wrong order
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 3", "Text 2", "Text 1"});
        
         // ✖ Last item does not match
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text"});
        
         // ✖ Locator points to the outer list element, not to the list items
         assertThat(page.locator("ul")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
         
        Parameters:
        expected - Expected string or RegExp or a list of those.
        Since:
        v1.20
      • hasText

        void hasText​(java.util.regex.Pattern[] expected,
                     LocatorAssertions.HasTextOptions options)
        Ensures the Locator points to an element with the given text. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator(".title")).hasText("Welcome, Test User");
         assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
         

        If you pass an array as an expected value, the expectations are:

        1. Locator resolves to a list of elements.
        2. The number of elements equals the number of expected values in the array.
        3. Elements from the list have text matching expected array values, one by one, in order.

        For example, consider the following list:

        Let's see how we can use the assertion:

        
         // ✓ Has the right items in the right order
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
        
         // ✖ Wrong order
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 3", "Text 2", "Text 1"});
        
         // ✖ Last item does not match
         assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text"});
        
         // ✖ Locator points to the outer list element, not to the list items
         assertThat(page.locator("ul")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
         
        Parameters:
        expected - Expected string or RegExp or a list of those.
        Since:
        v1.20
      • hasValue

        default void hasValue​(java.lang.String value)
        Ensures the Locator points to an element with the given input value. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator("input[type=number]")).hasValue(Pattern.compile("[0-9]"));
         
        Parameters:
        value - Expected value.
        Since:
        v1.20
      • hasValue

        void hasValue​(java.lang.String value,
                      LocatorAssertions.HasValueOptions options)
        Ensures the Locator points to an element with the given input value. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator("input[type=number]")).hasValue(Pattern.compile("[0-9]"));
         
        Parameters:
        value - Expected value.
        Since:
        v1.20
      • hasValue

        default void hasValue​(java.util.regex.Pattern value)
        Ensures the Locator points to an element with the given input value. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator("input[type=number]")).hasValue(Pattern.compile("[0-9]"));
         
        Parameters:
        value - Expected value.
        Since:
        v1.20
      • hasValue

        void hasValue​(java.util.regex.Pattern value,
                      LocatorAssertions.HasValueOptions options)
        Ensures the Locator points to an element with the given input value. You can use regular expressions for the value as well.

        **Usage**

        
         assertThat(page.locator("input[type=number]")).hasValue(Pattern.compile("[0-9]"));
         
        Parameters:
        value - Expected value.
        Since:
        v1.20
      • hasValues

        default void hasValues​(java.lang.String[] values)
        Ensures the Locator points to multi-select/combobox (i.e. a select with the multiple attribute) and the specified values are selected.

        **Usage**

        For example, given the following element:

        
         page.locator("id=favorite-colors").selectOption(["R", "G"]);
         assertThat(page.locator("id=favorite-colors")).hasValues(new Pattern[] { Pattern.compile("R"), Pattern.compile("G") });
         
        Parameters:
        values - Expected options currently selected.
        Since:
        v1.23
      • hasValues

        void hasValues​(java.lang.String[] values,
                       LocatorAssertions.HasValuesOptions options)
        Ensures the Locator points to multi-select/combobox (i.e. a select with the multiple attribute) and the specified values are selected.

        **Usage**

        For example, given the following element:

        
         page.locator("id=favorite-colors").selectOption(["R", "G"]);
         assertThat(page.locator("id=favorite-colors")).hasValues(new Pattern[] { Pattern.compile("R"), Pattern.compile("G") });
         
        Parameters:
        values - Expected options currently selected.
        Since:
        v1.23
      • hasValues

        default void hasValues​(java.util.regex.Pattern[] values)
        Ensures the Locator points to multi-select/combobox (i.e. a select with the multiple attribute) and the specified values are selected.

        **Usage**

        For example, given the following element:

        
         page.locator("id=favorite-colors").selectOption(["R", "G"]);
         assertThat(page.locator("id=favorite-colors")).hasValues(new Pattern[] { Pattern.compile("R"), Pattern.compile("G") });
         
        Parameters:
        values - Expected options currently selected.
        Since:
        v1.23
      • hasValues

        void hasValues​(java.util.regex.Pattern[] values,
                       LocatorAssertions.HasValuesOptions options)
        Ensures the Locator points to multi-select/combobox (i.e. a select with the multiple attribute) and the specified values are selected.

        **Usage**

        For example, given the following element:

        
         page.locator("id=favorite-colors").selectOption(["R", "G"]);
         assertThat(page.locator("id=favorite-colors")).hasValues(new Pattern[] { Pattern.compile("R"), Pattern.compile("G") });
         
        Parameters:
        values - Expected options currently selected.
        Since:
        v1.23