Interface LocatorAssertions
- All Known Implementing Classes:
LocatorAssertionsImpl
LocatorAssertions class provides assertion methods that can be used to make assertions about the
Locator state in the tests.
...
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
public class TestLocator {
...
@Test
void statusBecomesSubmitted() {
...
page.getByRole(AriaRole.BUTTON).click();
assertThat(page.locator(".status")).hasText("Submitted");
}
}
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic class -
Method Summary
Modifier and TypeMethodDescriptiondefault 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 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 voidEnsures theLocatorpoints to an element with given CSS classes.default voidEnsures 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 voidEnsures theLocatorpoints to an element with given CSS classes.default voidEnsures 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 voidEnsures 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 voidEnsures 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 voidEnsures 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 voidEnsures 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 voidEnsures theLocatorpoints to an element with the given text.default voidEnsures 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 voidEnsures theLocatorpoints to an element with the given text.default voidEnsures 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 voidEnsures 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 voidEnsures 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 voidEnsures theLocatorpoints to multi-select/combobox (i.e.voidhasValues(String[] values, LocatorAssertions.HasValuesOptions options) Ensures theLocatorpoints to multi-select/combobox (i.e.default voidEnsures theLocatorpoints to multi-select/combobox (i.e.voidhasValues(Pattern[] values, LocatorAssertions.HasValuesOptions options) Ensures theLocatorpoints to multi-select/combobox (i.e.default voidEnsures thatLocatorpoints to an attached DOM node.voidEnsures thatLocatorpoints to an attached DOM node.default voidEnsures theLocatorpoints to a checked input.voidEnsures theLocatorpoints to a checked input.default voidEnsures theLocatorpoints to a disabled element.voidEnsures theLocatorpoints to a disabled element.default voidEnsures theLocatorpoints to an editable element.voidEnsures 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 voidEnsures theLocatorpoints to an enabled element.voidEnsures theLocatorpoints to an enabled element.default voidEnsures theLocatorpoints to a focused DOM node.voidEnsures theLocatorpoints to a focused DOM node.default voidisHidden()Ensures thatLocatoreither does not resolve to any DOM node, or resolves to a non-visible one.voidEnsures thatLocatoreither does not resolve to any DOM node, or resolves to a non-visible one.default voidEnsures theLocatorpoints to an element that intersects viewport, according to the intersection observer API.voidEnsures theLocatorpoints to an element that intersects viewport, according to the intersection observer API.default voidvoidnot()Makes the assertion check for the opposite condition.
-
Method Details
-
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 attached DOM node.**Usage**
assertThat(page.getByText("Hidden text")).isAttached();- Since:
- v1.33
-
isAttached
Ensures thatLocatorpoints to an attached DOM node.**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
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
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
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
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
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
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
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
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
.invalid reference
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
Ensures thatLocatorpoints to an attached and visible DOM node.To check that at least one element from the list is visible, use
.invalid reference
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
Ensures theLocatorpoints 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:
- 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
Ensures theLocatorpoints 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:
- 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
Ensures theLocatorpoints 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:
- 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
Ensures theLocatorpoints 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:
- 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
Ensures theLocatorpoints 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:
- 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
Ensures theLocatorpoints 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:
- 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
Ensures theLocatorpoints 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:
- 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
Ensures theLocatorpoints 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:
- 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
-
hasAttribute
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
-
hasText
Ensures theLocatorpoints 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:
- 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
Ensures theLocatorpoints 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:
- 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
Ensures theLocatorpoints 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:
- 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
Ensures theLocatorpoints 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:
- 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
Ensures theLocatorpoints 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:
- 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
Ensures theLocatorpoints 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:
- 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
Ensures theLocatorpoints 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:
- 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
Ensures theLocatorpoints 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:
- 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
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
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
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
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
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
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
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
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
-