Class LocatorAssertionsImpl

    • Constructor Detail

      • LocatorAssertionsImpl

        public LocatorAssertionsImpl​(Locator locator)
      • LocatorAssertionsImpl

        private LocatorAssertionsImpl​(Locator locator,
                                      boolean isNot)
    • Method Detail

      • containsText

        public void containsText​(java.lang.String text,
                                 LocatorAssertions.ContainsTextOptions options)
        Description copied from interface: LocatorAssertions
        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"});
         
        Specified by:
        containsText in interface LocatorAssertions
        Parameters:
        text - Expected substring or RegExp or a list of those.
      • containsText

        public void containsText​(java.util.regex.Pattern pattern,
                                 LocatorAssertions.ContainsTextOptions options)
        Description copied from interface: LocatorAssertions
        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"});
         
        Specified by:
        containsText in interface LocatorAssertions
        Parameters:
        pattern - Expected substring or RegExp or a list of those.
      • containsText

        public void containsText​(java.lang.String[] strings,
                                 LocatorAssertions.ContainsTextOptions options)
        Description copied from interface: LocatorAssertions
        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"});
         
        Specified by:
        containsText in interface LocatorAssertions
        Parameters:
        strings - Expected substring or RegExp or a list of those.
      • containsText

        public void containsText​(java.util.regex.Pattern[] patterns,
                                 LocatorAssertions.ContainsTextOptions options)
        Description copied from interface: LocatorAssertions
        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"});
         
        Specified by:
        containsText in interface LocatorAssertions
        Parameters:
        patterns - Expected substring or RegExp or a list of those.
      • hasAttribute

        public void hasAttribute​(java.lang.String name,
                                 java.lang.String text,
                                 LocatorAssertions.HasAttributeOptions options)
        Description copied from interface: LocatorAssertions
        Ensures the Locator points to an element with given attribute.

        **Usage**

        
         assertThat(page.locator("input")).hasAttribute("type", "text");
         
        Specified by:
        hasAttribute in interface LocatorAssertions
        Parameters:
        name - Attribute name.
        text - Expected attribute value.
      • hasAttribute

        public void hasAttribute​(java.lang.String name,
                                 java.util.regex.Pattern pattern,
                                 LocatorAssertions.HasAttributeOptions options)
        Description copied from interface: LocatorAssertions
        Ensures the Locator points to an element with given attribute.

        **Usage**

        
         assertThat(page.locator("input")).hasAttribute("type", "text");
         
        Specified by:
        hasAttribute in interface LocatorAssertions
        Parameters:
        name - Attribute name.
        pattern - Expected attribute value.
      • hasClass

        public void hasClass​(java.lang.String text,
                             LocatorAssertions.HasClassOptions options)
        Description copied from interface: LocatorAssertions
        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"});
         
        Specified by:
        hasClass in interface LocatorAssertions
        Parameters:
        text - Expected class or RegExp or a list of those.
      • hasClass

        public void hasClass​(java.util.regex.Pattern pattern,
                             LocatorAssertions.HasClassOptions options)
        Description copied from interface: LocatorAssertions
        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"});
         
        Specified by:
        hasClass in interface LocatorAssertions
        Parameters:
        pattern - Expected class or RegExp or a list of those.
      • hasClass

        public void hasClass​(java.lang.String[] strings,
                             LocatorAssertions.HasClassOptions options)
        Description copied from interface: LocatorAssertions
        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"});
         
        Specified by:
        hasClass in interface LocatorAssertions
        Parameters:
        strings - Expected class or RegExp or a list of those.
      • hasClass

        public void hasClass​(java.util.regex.Pattern[] patterns,
                             LocatorAssertions.HasClassOptions options)
        Description copied from interface: LocatorAssertions
        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"});
         
        Specified by:
        hasClass in interface LocatorAssertions
        Parameters:
        patterns - Expected class or RegExp or a list of those.
      • hasCSS

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

        **Usage**

        
         assertThat(page.getByRole(AriaRole.BUTTON)).hasCSS("display", "flex");
         
        Specified by:
        hasCSS in interface LocatorAssertions
        Parameters:
        name - CSS property name.
        value - CSS property value.
      • hasCSS

        public void hasCSS​(java.lang.String name,
                           java.util.regex.Pattern pattern,
                           LocatorAssertions.HasCSSOptions options)
        Description copied from interface: LocatorAssertions
        Ensures the Locator resolves to an element with the given computed CSS style.

        **Usage**

        
         assertThat(page.getByRole(AriaRole.BUTTON)).hasCSS("display", "flex");
         
        Specified by:
        hasCSS in interface LocatorAssertions
        Parameters:
        name - CSS property name.
        pattern - CSS property value.
      • hasId

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

        **Usage**

        
         assertThat(page.getByRole(AriaRole.TEXTBOX)).hasId("lastname");
         
        Specified by:
        hasId in interface LocatorAssertions
        Parameters:
        id - Element id.
      • hasId

        public void hasId​(java.util.regex.Pattern pattern,
                          LocatorAssertions.HasIdOptions options)
        Description copied from interface: LocatorAssertions
        Ensures the Locator points to an element with the given DOM Node ID.

        **Usage**

        
         assertThat(page.getByRole(AriaRole.TEXTBOX)).hasId("lastname");
         
        Specified by:
        hasId in interface LocatorAssertions
        Parameters:
        pattern - Element id.
      • hasJSProperty

        public void hasJSProperty​(java.lang.String name,
                                  java.lang.Object value,
                                  LocatorAssertions.HasJSPropertyOptions options)
        Description copied from interface: LocatorAssertions
        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);
         
        Specified by:
        hasJSProperty in interface LocatorAssertions
        Parameters:
        name - Property name.
        value - Property value.
      • hasText

        public void hasText​(java.lang.String text,
                            LocatorAssertions.HasTextOptions options)
        Description copied from interface: LocatorAssertions
        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"});
         
        Specified by:
        hasText in interface LocatorAssertions
        Parameters:
        text - Expected string or RegExp or a list of those.
      • hasText

        public void hasText​(java.util.regex.Pattern pattern,
                            LocatorAssertions.HasTextOptions options)
        Description copied from interface: LocatorAssertions
        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"});
         
        Specified by:
        hasText in interface LocatorAssertions
        Parameters:
        pattern - Expected string or RegExp or a list of those.
      • hasText

        public void hasText​(java.lang.String[] strings,
                            LocatorAssertions.HasTextOptions options)
        Description copied from interface: LocatorAssertions
        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"});
         
        Specified by:
        hasText in interface LocatorAssertions
        Parameters:
        strings - Expected string or RegExp or a list of those.
      • hasText

        public void hasText​(java.util.regex.Pattern[] patterns,
                            LocatorAssertions.HasTextOptions options)
        Description copied from interface: LocatorAssertions
        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"});
         
        Specified by:
        hasText in interface LocatorAssertions
        Parameters:
        patterns - Expected string or RegExp or a list of those.
      • hasValue

        public void hasValue​(java.lang.String value,
                             LocatorAssertions.HasValueOptions options)
        Description copied from interface: LocatorAssertions
        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]"));
         
        Specified by:
        hasValue in interface LocatorAssertions
        Parameters:
        value - Expected value.
      • hasValue

        public void hasValue​(java.util.regex.Pattern pattern,
                             LocatorAssertions.HasValueOptions options)
        Description copied from interface: LocatorAssertions
        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]"));
         
        Specified by:
        hasValue in interface LocatorAssertions
        Parameters:
        pattern - Expected value.
      • hasValues

        public void hasValues​(java.lang.String[] values,
                              LocatorAssertions.HasValuesOptions options)
        Description copied from interface: LocatorAssertions
        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") });
         
        Specified by:
        hasValues in interface LocatorAssertions
        Parameters:
        values - Expected options currently selected.
      • hasValues

        public void hasValues​(java.util.regex.Pattern[] patterns,
                              LocatorAssertions.HasValuesOptions options)
        Description copied from interface: LocatorAssertions
        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") });
         
        Specified by:
        hasValues in interface LocatorAssertions
        Parameters:
        patterns - Expected options currently selected.
      • isDisabled

        public void isDisabled​(LocatorAssertions.IsDisabledOptions options)
        Description copied from interface: LocatorAssertions
        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();
         
        Specified by:
        isDisabled in interface LocatorAssertions
      • isInViewport

        public void isInViewport​(LocatorAssertions.IsInViewportOptions options)
        Description copied from interface: LocatorAssertions
        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));
         
        Specified by:
        isInViewport in interface LocatorAssertions
      • isVisible

        public void isVisible​(LocatorAssertions.IsVisibleOptions options)
        Description copied from interface: LocatorAssertions
        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();
         
        Specified by:
        isVisible in interface LocatorAssertions
      • expectTrue

        private void expectTrue​(java.lang.String expression,
                                java.lang.String message,
                                FrameExpectOptions options)
      • not

        public LocatorAssertions not()
        Description copied from interface: LocatorAssertions
        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");
         
        Specified by:
        not in interface LocatorAssertions
      • shouldIgnoreCase

        private static java.lang.Boolean shouldIgnoreCase​(java.lang.Object options)