public interface LocatorAssertions
LocatorAssertions class provides assertion methods that can be used to make assertions about the Locator state
in the tests. A new instance of LocatorAssertions is created by calling PlaywrightAssertions.assertThat():
{@code
...
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
public class TestLocator {
...| Modifier and Type | Interface and Description |
|---|---|
static class |
LocatorAssertions.ContainsTextOptions |
static class |
LocatorAssertions.HasAttributeOptions |
static class |
LocatorAssertions.HasClassOptions |
static class |
LocatorAssertions.HasCountOptions |
static class |
LocatorAssertions.HasCSSOptions |
static class |
LocatorAssertions.HasIdOptions |
static class |
LocatorAssertions.HasJSPropertyOptions |
static class |
LocatorAssertions.HasTextOptions |
static class |
LocatorAssertions.HasValueOptions |
static class |
LocatorAssertions.IsCheckedOptions |
static class |
LocatorAssertions.IsDisabledOptions |
static class |
LocatorAssertions.IsEditableOptions |
static class |
LocatorAssertions.IsEmptyOptions |
static class |
LocatorAssertions.IsEnabledOptions |
static class |
LocatorAssertions.IsFocusedOptions |
static class |
LocatorAssertions.IsHiddenOptions |
static class |
LocatorAssertions.IsVisibleOptions |
| Modifier and Type | Method and Description |
|---|---|
default void |
containsText(Pattern expected)
Ensures the
Locator points to an element that contains the given text. |
default void |
containsText(Pattern[] expected)
Ensures the
Locator points to an element that contains the given text. |
void |
containsText(Pattern[] expected,
LocatorAssertions.ContainsTextOptions options)
Ensures the
Locator points to an element that contains the given text. |
void |
containsText(Pattern expected,
LocatorAssertions.ContainsTextOptions options)
Ensures the
Locator points to an element that contains the given text. |
default void |
containsText(String expected)
Ensures the
Locator points to an element that contains the given text. |
default void |
containsText(String[] expected)
Ensures the
Locator points to an element that contains the given text. |
void |
containsText(String[] expected,
LocatorAssertions.ContainsTextOptions options)
Ensures the
Locator points to an element that contains the given text. |
void |
containsText(String expected,
LocatorAssertions.ContainsTextOptions options)
Ensures the
Locator points to an element that contains the given text. |
default void |
hasAttribute(String name,
Pattern value)
Ensures the
Locator points to an element with given attribute. |
void |
hasAttribute(String name,
Pattern value,
LocatorAssertions.HasAttributeOptions options)
Ensures the
Locator points to an element with given attribute. |
default void |
hasAttribute(String name,
String value)
Ensures the
Locator points to an element with given attribute. |
void |
hasAttribute(String name,
String value,
LocatorAssertions.HasAttributeOptions options)
Ensures the
Locator points to an element with given attribute. |
default void |
hasClass(Pattern expected)
Ensures the
Locator points to an element with given CSS class. |
default void |
hasClass(Pattern[] expected)
Ensures the
Locator points to an element with given CSS class. |
void |
hasClass(Pattern[] expected,
LocatorAssertions.HasClassOptions options)
Ensures the
Locator points to an element with given CSS class. |
void |
hasClass(Pattern expected,
LocatorAssertions.HasClassOptions options)
Ensures the
Locator points to an element with given CSS class. |
default void |
hasClass(String expected)
Ensures the
Locator points to an element with given CSS class. |
default void |
hasClass(String[] expected)
Ensures the
Locator points to an element with given CSS class. |
void |
hasClass(String[] expected,
LocatorAssertions.HasClassOptions options)
Ensures the
Locator points to an element with given CSS class. |
void |
hasClass(String expected,
LocatorAssertions.HasClassOptions options)
Ensures the
Locator points to an element with given CSS class. |
default void |
hasCount(int count)
Ensures the
Locator resolves to an exact number of DOM nodes. |
void |
hasCount(int count,
LocatorAssertions.HasCountOptions options)
Ensures the
Locator resolves to an exact number of DOM nodes. |
default void |
hasCSS(String name,
Pattern value)
Ensures the
Locator resolves to an element with the given computed CSS style. |
void |
hasCSS(String name,
Pattern value,
LocatorAssertions.HasCSSOptions options)
Ensures the
Locator resolves to an element with the given computed CSS style. |
default void |
hasCSS(String name,
String value)
Ensures the
Locator resolves to an element with the given computed CSS style. |
void |
hasCSS(String name,
String value,
LocatorAssertions.HasCSSOptions options)
Ensures the
Locator resolves to an element with the given computed CSS style. |
default void |
hasId(String id)
Ensures the
Locator points to an element with the given DOM Node ID. |
void |
hasId(String id,
LocatorAssertions.HasIdOptions options)
Ensures the
Locator points to an element with the given DOM Node ID. |
default void |
hasJSProperty(String name,
Object value)
Ensures the
Locator points to an element with given JavaScript property. |
void |
hasJSProperty(String name,
Object value,
LocatorAssertions.HasJSPropertyOptions options)
Ensures the
Locator points to an element with given JavaScript property. |
default void |
hasText(Pattern expected)
Ensures the
Locator points to an element with the given text. |
default void |
hasText(Pattern[] expected)
Ensures the
Locator points to an element with the given text. |
void |
hasText(Pattern[] expected,
LocatorAssertions.HasTextOptions options)
Ensures the
Locator points to an element with the given text. |
void |
hasText(Pattern expected,
LocatorAssertions.HasTextOptions options)
Ensures the
Locator points to an element with the given text. |
default void |
hasText(String expected)
Ensures the
Locator points to an element with the given text. |
default void |
hasText(String[] expected)
Ensures the
Locator points to an element with the given text. |
void |
hasText(String[] expected,
LocatorAssertions.HasTextOptions options)
Ensures the
Locator points to an element with the given text. |
void |
hasText(String expected,
LocatorAssertions.HasTextOptions options)
Ensures the
Locator points to an element with the given text. |
default void |
hasValue(Pattern value)
Ensures the
Locator points to an element with the given input value. |
void |
hasValue(Pattern value,
LocatorAssertions.HasValueOptions options)
Ensures the
Locator points to an element with the given input value. |
default void |
hasValue(String value)
Ensures the
Locator points to an element with the given input value. |
void |
hasValue(String value,
LocatorAssertions.HasValueOptions options)
Ensures the
Locator points to an element with the given input value. |
default void |
isChecked()
Ensures the
Locator points to a checked input. |
void |
isChecked(LocatorAssertions.IsCheckedOptions options)
Ensures the
Locator points to a checked input. |
default void |
isDisabled()
Ensures the
Locator points to a disabled element. |
void |
isDisabled(LocatorAssertions.IsDisabledOptions options)
Ensures the
Locator points to a disabled element. |
default void |
isEditable()
Ensures the
Locator points to an editable element. |
void |
isEditable(LocatorAssertions.IsEditableOptions options)
Ensures the
Locator points to an editable element. |
default void |
isEmpty()
Ensures the
Locator points to an empty editable element or to a DOM node that has no text. |
void |
isEmpty(LocatorAssertions.IsEmptyOptions options)
Ensures the
Locator points to an empty editable element or to a DOM node that has no text. |
default void |
isEnabled()
Ensures the
Locator points to an enabled element. |
void |
isEnabled(LocatorAssertions.IsEnabledOptions options)
Ensures the
Locator points to an enabled element. |
default void |
isFocused()
Ensures the
Locator points to a focused DOM node. |
void |
isFocused(LocatorAssertions.IsFocusedOptions options)
Ensures the
Locator points to a focused DOM node. |
default void |
isHidden()
Ensures the
Locator points to a hidden DOM node, which is the opposite of visible. |
void |
isHidden(LocatorAssertions.IsHiddenOptions options)
Ensures the
Locator points to a hidden DOM node, which is the opposite of visible. |
default void |
isVisible()
Ensures the
Locator points to a visible DOM
node. |
void |
isVisible(LocatorAssertions.IsVisibleOptions options)
Ensures the
Locator points to a visible DOM
node. |
LocatorAssertions |
not()
Makes the assertion check for the opposite condition.
|
default void containsText(String expected)
Locator points to an element that contains the given text. You can use regular expressions for the value
as well.
assertThat(page.locator(".title")).containsText("substring");
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .list-item")).containsText(new String[] {"Text 1", "Text 4", "Text 5"});
expected - Expected substring or RegExp or a list of those.void containsText(String expected, LocatorAssertions.ContainsTextOptions options)
Locator points to an element that contains the given text. You can use regular expressions for the value
as well.
assertThat(page.locator(".title")).containsText("substring");
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .list-item")).containsText(new String[] {"Text 1", "Text 4", "Text 5"});
expected - Expected substring or RegExp or a list of those.default void containsText(Pattern expected)
Locator points to an element that contains the given text. You can use regular expressions for the value
as well.
assertThat(page.locator(".title")).containsText("substring");
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .list-item")).containsText(new String[] {"Text 1", "Text 4", "Text 5"});
expected - Expected substring or RegExp or a list of those.void containsText(Pattern expected, LocatorAssertions.ContainsTextOptions options)
Locator points to an element that contains the given text. You can use regular expressions for the value
as well.
assertThat(page.locator(".title")).containsText("substring");
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .list-item")).containsText(new String[] {"Text 1", "Text 4", "Text 5"});
expected - Expected substring or RegExp or a list of those.default void containsText(String[] expected)
Locator points to an element that contains the given text. You can use regular expressions for the value
as well.
assertThat(page.locator(".title")).containsText("substring");
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .list-item")).containsText(new String[] {"Text 1", "Text 4", "Text 5"});
expected - Expected substring or RegExp or a list of those.void containsText(String[] expected, LocatorAssertions.ContainsTextOptions options)
Locator points to an element that contains the given text. You can use regular expressions for the value
as well.
assertThat(page.locator(".title")).containsText("substring");
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .list-item")).containsText(new String[] {"Text 1", "Text 4", "Text 5"});
expected - Expected substring or RegExp or a list of those.default void containsText(Pattern[] expected)
Locator points to an element that contains the given text. You can use regular expressions for the value
as well.
assertThat(page.locator(".title")).containsText("substring");
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .list-item")).containsText(new String[] {"Text 1", "Text 4", "Text 5"});
expected - Expected substring or RegExp or a list of those.void containsText(Pattern[] expected, LocatorAssertions.ContainsTextOptions options)
Locator points to an element that contains the given text. You can use regular expressions for the value
as well.
assertThat(page.locator(".title")).containsText("substring");
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .list-item")).containsText(new String[] {"Text 1", "Text 4", "Text 5"});
expected - Expected substring or RegExp or a list of those.default void hasAttribute(String name, String value)
Locator points to an element with given attribute.
assertThat(page.locator("input")).hasAttribute("type", "text");
name - Attribute name.value - Expected attribute value.void hasAttribute(String name, String value, LocatorAssertions.HasAttributeOptions options)
Locator points to an element with given attribute.
assertThat(page.locator("input")).hasAttribute("type", "text");
name - Attribute name.value - Expected attribute value.default void hasAttribute(String name, Pattern value)
Locator points to an element with given attribute.
assertThat(page.locator("input")).hasAttribute("type", "text");
name - Attribute name.value - Expected attribute value.void hasAttribute(String name, Pattern value, LocatorAssertions.HasAttributeOptions options)
Locator points to an element with given attribute.
assertThat(page.locator("input")).hasAttribute("type", "text");
name - Attribute name.value - Expected attribute value.default void hasClass(String expected)
Locator points to an element with given CSS class.
assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .component")).hasClass(new String[] {"component", "component selected", "component"});
expected - Expected class or RegExp or a list of those.void hasClass(String expected, LocatorAssertions.HasClassOptions options)
Locator points to an element with given CSS class.
assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .component")).hasClass(new String[] {"component", "component selected", "component"});
expected - Expected class or RegExp or a list of those.default void hasClass(Pattern expected)
Locator points to an element with given CSS class.
assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .component")).hasClass(new String[] {"component", "component selected", "component"});
expected - Expected class or RegExp or a list of those.void hasClass(Pattern expected, LocatorAssertions.HasClassOptions options)
Locator points to an element with given CSS class.
assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .component")).hasClass(new String[] {"component", "component selected", "component"});
expected - Expected class or RegExp or a list of those.default void hasClass(String[] expected)
Locator points to an element with given CSS class.
assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .component")).hasClass(new String[] {"component", "component selected", "component"});
expected - Expected class or RegExp or a list of those.void hasClass(String[] expected, LocatorAssertions.HasClassOptions options)
Locator points to an element with given CSS class.
assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .component")).hasClass(new String[] {"component", "component selected", "component"});
expected - Expected class or RegExp or a list of those.default void hasClass(Pattern[] expected)
Locator points to an element with given CSS class.
assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .component")).hasClass(new String[] {"component", "component selected", "component"});
expected - Expected class or RegExp or a list of those.void hasClass(Pattern[] expected, LocatorAssertions.HasClassOptions options)
Locator points to an element with given CSS class.
assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .component")).hasClass(new String[] {"component", "component selected", "component"});
expected - Expected class or RegExp or a list of those.default void hasCount(int count)
Locator resolves to an exact number of DOM nodes.
assertThat(page.locator("list > .component")).hasCount(3);
count - Expected count.void hasCount(int count,
LocatorAssertions.HasCountOptions options)
Locator resolves to an exact number of DOM nodes.
assertThat(page.locator("list > .component")).hasCount(3);
count - Expected count.default void hasCSS(String name, String value)
Locator resolves to an element with the given computed CSS style.
assertThat(page.locator("button")).hasCSS("display", "flex");
name - CSS property name.value - CSS property value.void hasCSS(String name, String value, LocatorAssertions.HasCSSOptions options)
Locator resolves to an element with the given computed CSS style.
assertThat(page.locator("button")).hasCSS("display", "flex");
name - CSS property name.value - CSS property value.default void hasCSS(String name, Pattern value)
Locator resolves to an element with the given computed CSS style.
assertThat(page.locator("button")).hasCSS("display", "flex");
name - CSS property name.value - CSS property value.void hasCSS(String name, Pattern value, LocatorAssertions.HasCSSOptions options)
Locator resolves to an element with the given computed CSS style.
assertThat(page.locator("button")).hasCSS("display", "flex");
name - CSS property name.value - CSS property value.default void hasId(String id)
Locator points to an element with the given DOM Node ID.
assertThat(page.locator("input")).hasId("lastname");
id - Element id.void hasId(String id, LocatorAssertions.HasIdOptions options)
Locator points to an element with the given DOM Node ID.
assertThat(page.locator("input")).hasId("lastname");
id - Element id.default void hasJSProperty(String name, Object value)
Locator points to an element with given JavaScript property. Note that this property can be of a primitive
type as well as a plain serializable JavaScript object.
assertThat(page.locator("input")).hasJSProperty("type", "text");
name - Property name.value - Property value.void hasJSProperty(String name, Object value, LocatorAssertions.HasJSPropertyOptions options)
Locator points to an element with given JavaScript property. Note that this property can be of a primitive
type as well as a plain serializable JavaScript object.
assertThat(page.locator("input")).hasJSProperty("type", "text");
name - Property name.value - Property value.default void hasText(String expected)
Locator points to an element with the given text. You can use regular expressions for the value as well.
assertThat(page.locator(".title")).hasText("Welcome, Test User");
assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .component")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
expected - Expected substring or RegExp or a list of those.void hasText(String expected, LocatorAssertions.HasTextOptions options)
Locator points to an element with the given text. You can use regular expressions for the value as well.
assertThat(page.locator(".title")).hasText("Welcome, Test User");
assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .component")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
expected - Expected substring or RegExp or a list of those.default void hasText(Pattern expected)
Locator points to an element with the given text. You can use regular expressions for the value as well.
assertThat(page.locator(".title")).hasText("Welcome, Test User");
assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .component")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
expected - Expected substring or RegExp or a list of those.void hasText(Pattern expected, LocatorAssertions.HasTextOptions options)
Locator points to an element with the given text. You can use regular expressions for the value as well.
assertThat(page.locator(".title")).hasText("Welcome, Test User");
assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .component")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
expected - Expected substring or RegExp or a list of those.default void hasText(String[] expected)
Locator points to an element with the given text. You can use regular expressions for the value as well.
assertThat(page.locator(".title")).hasText("Welcome, Test User");
assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .component")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
expected - Expected substring or RegExp or a list of those.void hasText(String[] expected, LocatorAssertions.HasTextOptions options)
Locator points to an element with the given text. You can use regular expressions for the value as well.
assertThat(page.locator(".title")).hasText("Welcome, Test User");
assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .component")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
expected - Expected substring or RegExp or a list of those.default void hasText(Pattern[] expected)
Locator points to an element with the given text. You can use regular expressions for the value as well.
assertThat(page.locator(".title")).hasText("Welcome, Test User");
assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .component")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
expected - Expected substring or RegExp or a list of those.void hasText(Pattern[] expected, LocatorAssertions.HasTextOptions options)
Locator points to an element with the given text. You can use regular expressions for the value as well.
assertThat(page.locator(".title")).hasText("Welcome, Test User");
assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
Note that if array is passed as an expected value, entire lists can be asserted:
assertThat(page.locator("list > .component")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
expected - Expected substring or RegExp or a list of those.default void hasValue(String value)
Locator points to an element with the given input value. You can use regular expressions for the value as
well.
assertThat(page.locator("input[type=number]")).hasValue(Pattern.compile("[0-9]"));
value - Expected value.void hasValue(String value, LocatorAssertions.HasValueOptions options)
Locator points to an element with the given input value. You can use regular expressions for the value as
well.
assertThat(page.locator("input[type=number]")).hasValue(Pattern.compile("[0-9]"));
value - Expected value.default void hasValue(Pattern value)
Locator points to an element with the given input value. You can use regular expressions for the value as
well.
assertThat(page.locator("input[type=number]")).hasValue(Pattern.compile("[0-9]"));
value - Expected value.void hasValue(Pattern value, LocatorAssertions.HasValueOptions options)
Locator points to an element with the given input value. You can use regular expressions for the value as
well.
assertThat(page.locator("input[type=number]")).hasValue(Pattern.compile("[0-9]"));
value - Expected value.default void isChecked()
Locator points to a checked input.
assertThat(page.locator(".subscribe")).isChecked();
void isChecked(LocatorAssertions.IsCheckedOptions options)
Locator points to a checked input.
assertThat(page.locator(".subscribe")).isChecked();
default void isDisabled()
Locator points to a disabled element.
assertThat(page.locator("button.submit")).isDisabled();
void isDisabled(LocatorAssertions.IsDisabledOptions options)
Locator points to a disabled element.
assertThat(page.locator("button.submit")).isDisabled();
default void isEditable()
Locator points to an editable element.
assertThat(page.locator("input")).isEditable();
void isEditable(LocatorAssertions.IsEditableOptions options)
Locator points to an editable element.
assertThat(page.locator("input")).isEditable();
default void isEmpty()
Locator points to an empty editable element or to a DOM node that has no text.
assertThat(page.locator("div.warning")).isEmpty();
void isEmpty(LocatorAssertions.IsEmptyOptions options)
Locator points to an empty editable element or to a DOM node that has no text.
assertThat(page.locator("div.warning")).isEmpty();
default void isEnabled()
Locator points to an enabled element.
assertThat(page.locator("button.submit")).isEnabled();
void isEnabled(LocatorAssertions.IsEnabledOptions options)
Locator points to an enabled element.
assertThat(page.locator("button.submit")).isEnabled();
default void isFocused()
Locator points to a focused DOM node.
assertThat(page.locator("input")).isFocused();
void isFocused(LocatorAssertions.IsFocusedOptions options)
Locator points to a focused DOM node.
assertThat(page.locator("input")).isFocused();
default void isHidden()
Locator points to a hidden DOM node, which is the opposite of visible.
assertThat(page.locator(".my-element")).isHidden();
void isHidden(LocatorAssertions.IsHiddenOptions options)
Locator points to a hidden DOM node, which is the opposite of visible.
assertThat(page.locator(".my-element")).isHidden();
default void isVisible()
Locator points to a visible DOM
node.
assertThat(page.locator(".my-element")).isVisible();
void isVisible(LocatorAssertions.IsVisibleOptions options)
Locator points to a visible DOM
node.
assertThat(page.locator(".my-element")).isVisible();
LocatorAssertions not()
"error":
assertThat(locator).not().containsText("error");
Copyright © 2021. All rights reserved.