Interface LocatorAssertions
-
public interface LocatorAssertionsTheLocatorAssertionsclass provides assertion methods that can be used to make assertions about theLocatorstate in the tests.{@code ... import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat; public class TestLocator { ...
-
-
Nested Class Summary
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidcontainsText(String expected)Ensures theLocatorpoints to an element that contains the given text.default voidcontainsText(String[] expected)Ensures theLocatorpoints to an element that contains the given text.voidcontainsText(String[] expected, LocatorAssertions.ContainsTextOptions options)Ensures theLocatorpoints to an element that contains the given text.voidcontainsText(String expected, LocatorAssertions.ContainsTextOptions options)Ensures theLocatorpoints to an element that contains the given text.default voidcontainsText(Pattern expected)Ensures theLocatorpoints to an element that contains the given text.default voidcontainsText(Pattern[] expected)Ensures theLocatorpoints to an element that contains the given text.voidcontainsText(Pattern[] expected, LocatorAssertions.ContainsTextOptions options)Ensures theLocatorpoints to an element that contains the given text.voidcontainsText(Pattern expected, LocatorAssertions.ContainsTextOptions options)Ensures theLocatorpoints to an element that contains the given text.default voidhasAccessibleDescription(String description)Ensures theLocatorpoints to an element with a given accessible description.voidhasAccessibleDescription(String description, LocatorAssertions.HasAccessibleDescriptionOptions options)Ensures theLocatorpoints to an element with a given accessible description.default voidhasAccessibleDescription(Pattern description)Ensures theLocatorpoints to an element with a given accessible description.voidhasAccessibleDescription(Pattern description, LocatorAssertions.HasAccessibleDescriptionOptions options)Ensures theLocatorpoints to an element with a given accessible description.default voidhasAccessibleName(String name)Ensures theLocatorpoints to an element with a given accessible name.voidhasAccessibleName(String name, LocatorAssertions.HasAccessibleNameOptions options)Ensures theLocatorpoints to an element with a given accessible name.default voidhasAccessibleName(Pattern name)Ensures theLocatorpoints to an element with a given accessible name.voidhasAccessibleName(Pattern name, LocatorAssertions.HasAccessibleNameOptions options)Ensures theLocatorpoints to an element with a given accessible name.default voidhasAttribute(String name, String value)Ensures theLocatorpoints to an element with given attribute.voidhasAttribute(String name, String value, LocatorAssertions.HasAttributeOptions options)Ensures theLocatorpoints to an element with given attribute.default voidhasAttribute(String name, Pattern value)Ensures theLocatorpoints to an element with given attribute.voidhasAttribute(String name, Pattern value, LocatorAssertions.HasAttributeOptions options)Ensures theLocatorpoints to an element with given attribute.default voidhasClass(String expected)Ensures theLocatorpoints to an element with given CSS classes.default voidhasClass(String[] expected)Ensures theLocatorpoints to an element with given CSS classes.voidhasClass(String[] expected, LocatorAssertions.HasClassOptions options)Ensures theLocatorpoints to an element with given CSS classes.voidhasClass(String expected, LocatorAssertions.HasClassOptions options)Ensures theLocatorpoints to an element with given CSS classes.default voidhasClass(Pattern expected)Ensures theLocatorpoints to an element with given CSS classes.default voidhasClass(Pattern[] expected)Ensures theLocatorpoints to an element with given CSS classes.voidhasClass(Pattern[] expected, LocatorAssertions.HasClassOptions options)Ensures theLocatorpoints to an element with given CSS classes.voidhasClass(Pattern expected, LocatorAssertions.HasClassOptions options)Ensures theLocatorpoints to an element with given CSS classes.default voidhasCount(int count)Ensures theLocatorresolves to an exact number of DOM nodes.voidhasCount(int count, LocatorAssertions.HasCountOptions options)Ensures theLocatorresolves to an exact number of DOM nodes.default voidhasCSS(String name, String value)Ensures theLocatorresolves to an element with the given computed CSS style.voidhasCSS(String name, String value, LocatorAssertions.HasCSSOptions options)Ensures theLocatorresolves to an element with the given computed CSS style.default voidhasCSS(String name, Pattern value)Ensures theLocatorresolves to an element with the given computed CSS style.voidhasCSS(String name, Pattern value, LocatorAssertions.HasCSSOptions options)Ensures theLocatorresolves to an element with the given computed CSS style.default voidhasId(String id)Ensures theLocatorpoints to an element with the given DOM Node ID.voidhasId(String id, LocatorAssertions.HasIdOptions options)Ensures theLocatorpoints to an element with the given DOM Node ID.default voidhasId(Pattern id)Ensures theLocatorpoints to an element with the given DOM Node ID.voidhasId(Pattern id, LocatorAssertions.HasIdOptions options)Ensures theLocatorpoints to an element with the given DOM Node ID.default voidhasJSProperty(String name, Object value)Ensures theLocatorpoints to an element with given JavaScript property.voidhasJSProperty(String name, Object value, LocatorAssertions.HasJSPropertyOptions options)Ensures theLocatorpoints to an element with given JavaScript property.default voidhasRole(AriaRole role)Ensures theLocatorpoints to an element with a given ARIA role.voidhasRole(AriaRole role, LocatorAssertions.HasRoleOptions options)Ensures theLocatorpoints to an element with a given ARIA role.default voidhasText(String expected)Ensures theLocatorpoints to an element with the given text.default voidhasText(String[] expected)Ensures theLocatorpoints to an element with the given text.voidhasText(String[] expected, LocatorAssertions.HasTextOptions options)Ensures theLocatorpoints to an element with the given text.voidhasText(String expected, LocatorAssertions.HasTextOptions options)Ensures theLocatorpoints to an element with the given text.default voidhasText(Pattern expected)Ensures theLocatorpoints to an element with the given text.default voidhasText(Pattern[] expected)Ensures theLocatorpoints to an element with the given text.voidhasText(Pattern[] expected, LocatorAssertions.HasTextOptions options)Ensures theLocatorpoints to an element with the given text.voidhasText(Pattern expected, LocatorAssertions.HasTextOptions options)Ensures theLocatorpoints to an element with the given text.default voidhasValue(String value)Ensures theLocatorpoints to an element with the given input value.voidhasValue(String value, LocatorAssertions.HasValueOptions options)Ensures theLocatorpoints to an element with the given input value.default voidhasValue(Pattern value)Ensures theLocatorpoints to an element with the given input value.voidhasValue(Pattern value, LocatorAssertions.HasValueOptions options)Ensures theLocatorpoints to an element with the given input value.default voidhasValues(String[] values)Ensures theLocatorpoints to multi-select/combobox (i.e.voidhasValues(String[] values, LocatorAssertions.HasValuesOptions options)Ensures theLocatorpoints to multi-select/combobox (i.e.default voidhasValues(Pattern[] values)Ensures theLocatorpoints to multi-select/combobox (i.e.voidhasValues(Pattern[] values, LocatorAssertions.HasValuesOptions options)Ensures theLocatorpoints to multi-select/combobox (i.e.default voidisAttached()Ensures thatLocatorpoints to an element that is connected to a Document or a ShadowRoot.voidisAttached(LocatorAssertions.IsAttachedOptions options)Ensures thatLocatorpoints to an element that is connected to a Document or a ShadowRoot.default voidisChecked()Ensures theLocatorpoints to a checked input.voidisChecked(LocatorAssertions.IsCheckedOptions options)Ensures theLocatorpoints to a checked input.default voidisDisabled()Ensures theLocatorpoints to a disabled element.voidisDisabled(LocatorAssertions.IsDisabledOptions options)Ensures theLocatorpoints to a disabled element.default voidisEditable()Ensures theLocatorpoints to an editable element.voidisEditable(LocatorAssertions.IsEditableOptions options)Ensures theLocatorpoints to an editable element.default voidisEmpty()Ensures theLocatorpoints to an empty editable element or to a DOM node that has no text.voidisEmpty(LocatorAssertions.IsEmptyOptions options)Ensures theLocatorpoints to an empty editable element or to a DOM node that has no text.default voidisEnabled()Ensures theLocatorpoints to an enabled element.voidisEnabled(LocatorAssertions.IsEnabledOptions options)Ensures theLocatorpoints to an enabled element.default voidisFocused()Ensures theLocatorpoints to a focused DOM node.voidisFocused(LocatorAssertions.IsFocusedOptions options)Ensures theLocatorpoints to a focused DOM node.default voidisHidden()Ensures thatLocatoreither does not resolve to any DOM node, or resolves to a non-visible one.voidisHidden(LocatorAssertions.IsHiddenOptions options)Ensures thatLocatoreither does not resolve to any DOM node, or resolves to a non-visible one.default voidisInViewport()Ensures theLocatorpoints to an element that intersects viewport, according to the intersection observer API.voidisInViewport(LocatorAssertions.IsInViewportOptions options)Ensures theLocatorpoints to an element that intersects viewport, according to the intersection observer API.default voidisVisible()Ensures thatLocatorpoints to an attached and visible DOM node.voidisVisible(LocatorAssertions.IsVisibleOptions options)Ensures thatLocatorpoints to an attached and visible DOM node.LocatorAssertionsnot()Makes the assertion check for the opposite condition.
-
-
-
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 thatLocatorpoints to an element that is connected to a Document or a ShadowRoot.Usage
assertThat(page.getByText("Hidden text")).isAttached();- Since:
- v1.33
-
isAttached
void isAttached(LocatorAssertions.IsAttachedOptions options)
Ensures thatLocatorpoints to an element that is connected to a Document or a ShadowRoot.Usage
assertThat(page.getByText("Hidden text")).isAttached();- Since:
- v1.33
-
isChecked
default void isChecked()
Ensures theLocatorpoints to a checked input.Usage
assertThat(page.getByLabel("Subscribe to newsletter")).isChecked();- Since:
- v1.20
-
isChecked
void isChecked(LocatorAssertions.IsCheckedOptions options)
Ensures theLocatorpoints to a checked input.Usage
assertThat(page.getByLabel("Subscribe to newsletter")).isChecked();- Since:
- v1.20
-
isDisabled
default void isDisabled()
Ensures theLocatorpoints 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 HTMLbutton,input,select,textarea,option,optgroupcan 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 theLocatorpoints 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 HTMLbutton,input,select,textarea,option,optgroupcan 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 theLocatorpoints to an editable element.Usage
assertThat(page.getByRole(AriaRole.TEXTBOX)).isEditable();- Since:
- v1.20
-
isEditable
void isEditable(LocatorAssertions.IsEditableOptions options)
Ensures theLocatorpoints to an editable element.Usage
assertThat(page.getByRole(AriaRole.TEXTBOX)).isEditable();- Since:
- v1.20
-
isEmpty
default void isEmpty()
Ensures theLocatorpoints 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 theLocatorpoints 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 theLocatorpoints to an enabled element.Usage
assertThat(page.locator("button.submit")).isEnabled();- Since:
- v1.20
-
isEnabled
void isEnabled(LocatorAssertions.IsEnabledOptions options)
Ensures theLocatorpoints to an enabled element.Usage
assertThat(page.locator("button.submit")).isEnabled();- Since:
- v1.20
-
isFocused
default void isFocused()
Ensures theLocatorpoints to a focused DOM node.Usage
assertThat(page.getByRole(AriaRole.TEXTBOX)).isFocused();- Since:
- v1.20
-
isFocused
void isFocused(LocatorAssertions.IsFocusedOptions options)
Ensures theLocatorpoints to a focused DOM node.Usage
assertThat(page.getByRole(AriaRole.TEXTBOX)).isFocused();- Since:
- v1.20
-
isHidden
default void isHidden()
Ensures thatLocatoreither 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 thatLocatoreither 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 theLocatorpoints 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 theLocatorpoints 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 thatLocatorpoints 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 thatLocatorpoints 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(String expected)
Ensures theLocatorpoints to an element that contains the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.Details
When
expectedparameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and in the expected string before matching. When regular expression is used, the actual text is matched as is.Usage
assertThat(page.locator(".title")).containsText("substring");If you pass an array as an expected value, the expectations are:
- Locator resolves to a list of elements.
- Elements from a **subset** of this list contain text from the expected array, respectively.
- The matching subset of elements has the same order as the expected array.
- 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(String expected, LocatorAssertions.ContainsTextOptions options)
Ensures theLocatorpoints to an element that contains the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.Details
When
expectedparameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and in the expected string before matching. When regular expression is used, the actual text is matched as is.Usage
assertThat(page.locator(".title")).containsText("substring");If you pass an array as an expected value, the expectations are:
- Locator resolves to a list of elements.
- Elements from a **subset** of this list contain text from the expected array, respectively.
- The matching subset of elements has the same order as the expected array.
- 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(Pattern expected)
Ensures theLocatorpoints to an element that contains the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.Details
When
expectedparameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and in the expected string before matching. When regular expression is used, the actual text is matched as is.Usage
assertThat(page.locator(".title")).containsText("substring");If you pass an array as an expected value, the expectations are:
- Locator resolves to a list of elements.
- Elements from a **subset** of this list contain text from the expected array, respectively.
- The matching subset of elements has the same order as the expected array.
- 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(Pattern expected, LocatorAssertions.ContainsTextOptions options)
Ensures theLocatorpoints to an element that contains the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.Details
When
expectedparameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and in the expected string before matching. When regular expression is used, the actual text is matched as is.Usage
assertThat(page.locator(".title")).containsText("substring");If you pass an array as an expected value, the expectations are:
- Locator resolves to a list of elements.
- Elements from a **subset** of this list contain text from the expected array, respectively.
- The matching subset of elements has the same order as the expected array.
- 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(String[] expected)
Ensures theLocatorpoints to an element that contains the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.Details
When
expectedparameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and in the expected string before matching. When regular expression is used, the actual text is matched as is.Usage
assertThat(page.locator(".title")).containsText("substring");If you pass an array as an expected value, the expectations are:
- Locator resolves to a list of elements.
- Elements from a **subset** of this list contain text from the expected array, respectively.
- The matching subset of elements has the same order as the expected array.
- 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(String[] expected, LocatorAssertions.ContainsTextOptions options)
Ensures theLocatorpoints to an element that contains the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.Details
When
expectedparameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and in the expected string before matching. When regular expression is used, the actual text is matched as is.Usage
assertThat(page.locator(".title")).containsText("substring");If you pass an array as an expected value, the expectations are:
- Locator resolves to a list of elements.
- Elements from a **subset** of this list contain text from the expected array, respectively.
- The matching subset of elements has the same order as the expected array.
- 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(Pattern[] expected)
Ensures theLocatorpoints to an element that contains the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.Details
When
expectedparameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and in the expected string before matching. When regular expression is used, the actual text is matched as is.Usage
assertThat(page.locator(".title")).containsText("substring");If you pass an array as an expected value, the expectations are:
- Locator resolves to a list of elements.
- Elements from a **subset** of this list contain text from the expected array, respectively.
- The matching subset of elements has the same order as the expected array.
- 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(Pattern[] expected, LocatorAssertions.ContainsTextOptions options)
Ensures theLocatorpoints to an element that contains the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.Details
When
expectedparameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and in the expected string before matching. When regular expression is used, the actual text is matched as is.Usage
assertThat(page.locator(".title")).containsText("substring");If you pass an array as an expected value, the expectations are:
- Locator resolves to a list of elements.
- Elements from a **subset** of this list contain text from the expected array, respectively.
- The matching subset of elements has the same order as the expected array.
- 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
-
hasAccessibleDescription
default void hasAccessibleDescription(String description)
Ensures theLocatorpoints to an element with a given accessible description.Usage
Locator locator = page.getByTestId("save-button"); assertThat(locator).hasAccessibleDescription("Save results to disk");- Parameters:
description- Expected accessible description.- Since:
- v1.44
-
hasAccessibleDescription
void hasAccessibleDescription(String description, LocatorAssertions.HasAccessibleDescriptionOptions options)
Ensures theLocatorpoints to an element with a given accessible description.Usage
Locator locator = page.getByTestId("save-button"); assertThat(locator).hasAccessibleDescription("Save results to disk");- Parameters:
description- Expected accessible description.- Since:
- v1.44
-
hasAccessibleDescription
default void hasAccessibleDescription(Pattern description)
Ensures theLocatorpoints to an element with a given accessible description.Usage
Locator locator = page.getByTestId("save-button"); assertThat(locator).hasAccessibleDescription("Save results to disk");- Parameters:
description- Expected accessible description.- Since:
- v1.44
-
hasAccessibleDescription
void hasAccessibleDescription(Pattern description, LocatorAssertions.HasAccessibleDescriptionOptions options)
Ensures theLocatorpoints to an element with a given accessible description.Usage
Locator locator = page.getByTestId("save-button"); assertThat(locator).hasAccessibleDescription("Save results to disk");- Parameters:
description- Expected accessible description.- Since:
- v1.44
-
hasAccessibleName
default void hasAccessibleName(String name)
Ensures theLocatorpoints to an element with a given accessible name.Usage
Locator locator = page.getByTestId("save-button"); assertThat(locator).hasAccessibleName("Save to disk");- Parameters:
name- Expected accessible name.- Since:
- v1.44
-
hasAccessibleName
void hasAccessibleName(String name, LocatorAssertions.HasAccessibleNameOptions options)
Ensures theLocatorpoints to an element with a given accessible name.Usage
Locator locator = page.getByTestId("save-button"); assertThat(locator).hasAccessibleName("Save to disk");- Parameters:
name- Expected accessible name.- Since:
- v1.44
-
hasAccessibleName
default void hasAccessibleName(Pattern name)
Ensures theLocatorpoints to an element with a given accessible name.Usage
Locator locator = page.getByTestId("save-button"); assertThat(locator).hasAccessibleName("Save to disk");- Parameters:
name- Expected accessible name.- Since:
- v1.44
-
hasAccessibleName
void hasAccessibleName(Pattern name, LocatorAssertions.HasAccessibleNameOptions options)
Ensures theLocatorpoints to an element with a given accessible name.Usage
Locator locator = page.getByTestId("save-button"); assertThat(locator).hasAccessibleName("Save to disk");- Parameters:
name- Expected accessible name.- Since:
- v1.44
-
hasAttribute
default void hasAttribute(String name, String value)
Ensures theLocatorpoints 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(String name, String value, LocatorAssertions.HasAttributeOptions options)
Ensures theLocatorpoints 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(String name, Pattern value)
Ensures theLocatorpoints 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(String name, Pattern value, LocatorAssertions.HasAttributeOptions options)
Ensures theLocatorpoints 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(String expected)
Ensures theLocatorpoints 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(String expected, LocatorAssertions.HasClassOptions options)
Ensures theLocatorpoints 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(Pattern expected)
Ensures theLocatorpoints 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(Pattern expected, LocatorAssertions.HasClassOptions options)
Ensures theLocatorpoints 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(String[] expected)
Ensures theLocatorpoints 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(String[] expected, LocatorAssertions.HasClassOptions options)
Ensures theLocatorpoints 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(Pattern[] expected)
Ensures theLocatorpoints 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(Pattern[] expected, LocatorAssertions.HasClassOptions options)
Ensures theLocatorpoints 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 theLocatorresolves 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 theLocatorresolves 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(String name, String value)
Ensures theLocatorresolves 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(String name, String value, LocatorAssertions.HasCSSOptions options)
Ensures theLocatorresolves 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(String name, Pattern value)
Ensures theLocatorresolves 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(String name, Pattern value, LocatorAssertions.HasCSSOptions options)
Ensures theLocatorresolves 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(String id)
Ensures theLocatorpoints 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(String id, LocatorAssertions.HasIdOptions options)
Ensures theLocatorpoints 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(Pattern id)
Ensures theLocatorpoints 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(Pattern id, LocatorAssertions.HasIdOptions options)
Ensures theLocatorpoints 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(String name, Object value)
Ensures theLocatorpoints 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(String name, Object value, LocatorAssertions.HasJSPropertyOptions options)
Ensures theLocatorpoints 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
-
hasRole
default void hasRole(AriaRole role)
Ensures theLocatorpoints to an element with a given ARIA role.Note that role is matched as a string, disregarding the ARIA role hierarchy. For example, asserting a superclass role
"checkbox"on an element with a subclass role"switch"will fail.Usage
Locator locator = page.getByTestId("save-button"); assertThat(locator).hasRole(AriaRole.BUTTON);- Parameters:
role- Required aria role.- Since:
- v1.44
-
hasRole
void hasRole(AriaRole role, LocatorAssertions.HasRoleOptions options)
Ensures theLocatorpoints to an element with a given ARIA role.Note that role is matched as a string, disregarding the ARIA role hierarchy. For example, asserting a superclass role
"checkbox"on an element with a subclass role"switch"will fail.Usage
Locator locator = page.getByTestId("save-button"); assertThat(locator).hasRole(AriaRole.BUTTON);- Parameters:
role- Required aria role.- Since:
- v1.44
-
hasText
default void hasText(String expected)
Ensures theLocatorpoints to an element with the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.Details
When
expectedparameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and in the expected string before matching. When regular expression is used, the actual text is matched as is.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:
- Locator resolves to a list of elements.
- The number of elements equals the number of expected values in the array.
- 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(String expected, LocatorAssertions.HasTextOptions options)
Ensures theLocatorpoints to an element with the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.Details
When
expectedparameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and in the expected string before matching. When regular expression is used, the actual text is matched as is.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:
- Locator resolves to a list of elements.
- The number of elements equals the number of expected values in the array.
- 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(Pattern expected)
Ensures theLocatorpoints to an element with the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.Details
When
expectedparameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and in the expected string before matching. When regular expression is used, the actual text is matched as is.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:
- Locator resolves to a list of elements.
- The number of elements equals the number of expected values in the array.
- 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(Pattern expected, LocatorAssertions.HasTextOptions options)
Ensures theLocatorpoints to an element with the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.Details
When
expectedparameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and in the expected string before matching. When regular expression is used, the actual text is matched as is.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:
- Locator resolves to a list of elements.
- The number of elements equals the number of expected values in the array.
- 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(String[] expected)
Ensures theLocatorpoints to an element with the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.Details
When
expectedparameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and in the expected string before matching. When regular expression is used, the actual text is matched as is.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:
- Locator resolves to a list of elements.
- The number of elements equals the number of expected values in the array.
- 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(String[] expected, LocatorAssertions.HasTextOptions options)
Ensures theLocatorpoints to an element with the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.Details
When
expectedparameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and in the expected string before matching. When regular expression is used, the actual text is matched as is.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:
- Locator resolves to a list of elements.
- The number of elements equals the number of expected values in the array.
- 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(Pattern[] expected)
Ensures theLocatorpoints to an element with the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.Details
When
expectedparameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and in the expected string before matching. When regular expression is used, the actual text is matched as is.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:
- Locator resolves to a list of elements.
- The number of elements equals the number of expected values in the array.
- 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(Pattern[] expected, LocatorAssertions.HasTextOptions options)
Ensures theLocatorpoints to an element with the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.Details
When
expectedparameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and in the expected string before matching. When regular expression is used, the actual text is matched as is.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:
- Locator resolves to a list of elements.
- The number of elements equals the number of expected values in the array.
- 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(String value)
Ensures theLocatorpoints 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(String value, LocatorAssertions.HasValueOptions options)
Ensures theLocatorpoints 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(Pattern value)
Ensures theLocatorpoints 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(Pattern value, LocatorAssertions.HasValueOptions options)
Ensures theLocatorpoints 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(String[] values)
Ensures theLocatorpoints to multi-select/combobox (i.e. aselectwith themultipleattribute) 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(String[] values, LocatorAssertions.HasValuesOptions options)
Ensures theLocatorpoints to multi-select/combobox (i.e. aselectwith themultipleattribute) 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(Pattern[] values)
Ensures theLocatorpoints to multi-select/combobox (i.e. aselectwith themultipleattribute) 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(Pattern[] values, LocatorAssertions.HasValuesOptions options)
Ensures theLocatorpoints to multi-select/combobox (i.e. aselectwith themultipleattribute) 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
-
-