public abstract class Condition
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static Condition |
appear
Synonym for
visible - may be used for better readability |
static Condition |
appears
|
static Condition |
checked
Checks that checkbox is checked
|
static Condition |
disabled
Checks that element is disabled
|
static Condition |
disappear
Synonym for
hidden - may be used for better readability: |
static Condition |
disappears
|
static Condition |
empty
1) For input element, check that value is missing or empty
|
static Condition |
enabled
Checks that element is not disabled
|
static Condition |
exist
Check if element exist.
|
static Condition |
focused
Check if browser focus is currently in given element.
|
static Condition |
hidden
Checks that element is not visible or does not exists.
|
static Condition |
image
Check if image is loaded.
|
static Condition |
readonly
Check if element has "readonly" attribute (with any value)
|
static Condition |
selected
Checks that element is selected (inputs like drop-downs etc.)
|
static Condition |
visible
Checks if element is visible
|
| Constructor and Description |
|---|
Condition(java.lang.String name) |
Condition(java.lang.String name,
boolean absentElementMatchesCondition) |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
actualValue(Driver driver,
WebElement element)
If element didn't match the condition, returns the actual value of element.
|
static Condition |
and(java.lang.String name,
Condition... conditions)
Check if element matches ALL given conditions.
|
abstract boolean |
apply(Driver driver,
WebElement element)
Check if given element matches this condition.
|
boolean |
applyNull() |
static Condition |
attribute(java.lang.String attributeName)
Check if element has given attribute (with any value)
|
static Condition |
attribute(java.lang.String attributeName,
java.lang.String expectedAttributeValue)
Sample:
$("#mydiv").shouldHave(attribute("fileId", "12345")); |
static Condition |
attributeMatching(java.lang.String attributeName,
java.lang.String attributeRegex)
Assert that given element's attribute matches given regular expression
|
static Condition |
be(Condition delegate)
Used to form human-readable condition expression
Example element.should(be(visible),have(text("abc"))
|
Condition |
because(java.lang.String message)
Should be used for explaining the reason of condition
|
static Condition |
cssClass(java.lang.String cssClass)
Asserts that element has the given class.
|
static Condition |
cssValue(java.lang.String propertyName,
java.lang.String expectedValue)
Checks if css property (style) applies for the element.
|
static Condition |
exactOwnText(java.lang.String text)
Assert that element has given text (without checking child elements).
|
static Condition |
exactText(java.lang.String text)
Assert that element has exactly (case insensitive) given text
|
static Condition |
exactTextCaseSensitive(java.lang.String text)
Assert that element has exactly the given text
|
static Condition |
exactValue(java.lang.String value)
Sample:
$("#input").shouldHave(exactValue("John")); |
java.lang.String |
getName() |
static Condition |
have(Condition delegate)
Used to form human-readable condition expression
Example element.should(be(visible),have(text("abc"))
|
static Condition |
href(java.lang.String href)
Sample:
$("#mydiv").shouldHave(href("/one/two/three.pdf")); |
static Condition |
id(java.lang.String id)
Sample:
$("#input").shouldHave(id("myForm")) |
static Condition |
match(java.lang.String description,
java.util.function.Predicate<WebElement> predicate)
Checks if element matches the given predicate.
|
static Condition |
matchesText(java.lang.String text)
Deprecated.
|
static Condition |
matchText(java.lang.String regex)
Assert that given element's text matches given regular expression
|
boolean |
missingElementSatisfiesCondition() |
static Condition |
name(java.lang.String name)
Asserts the name attribute of the element to be exact string
|
Condition |
negate() |
static Condition |
not(Condition condition)
Negate given condition.
|
static Condition |
or(java.lang.String name,
Condition... conditions)
Check if element matches ANY of given conditions.
|
static Condition |
ownText(java.lang.String text)
Assert that element contains given text (without checking child elements).
|
static Condition |
pseudo(java.lang.String pseudoElementName,
java.lang.String expectedValue)
Check that element has given the "content" property of the pseudo-element
|
static Condition |
pseudo(java.lang.String pseudoElementName,
java.lang.String propertyName,
java.lang.String expectedValue)
Check that element has given the property value of the pseudo-element
|
static Condition |
selectedText(java.lang.String expectedText)
Checks on a element that exactly given text is selected (=marked with mouse/keyboard)
|
static Condition |
text(java.lang.String text)
Assert that element contains given text as a substring.
|
static Condition |
textCaseSensitive(java.lang.String text)
Assert that element contains given text as a case sensitive substring
|
java.lang.String |
toString() |
static Condition |
type(java.lang.String type)
Asserts the type attribute of the element to be exact string
|
static Condition |
value(java.lang.String expectedValue)
Assert that element contains given "value" attribute as substring
NB! Ignores difference in non-visible characters like spaces, non-breakable spaces, tabs, newlines etc.
|
public static final Condition visible
Sample: $("input").shouldBe(visible);
public static final Condition exist
Sample: $("input").should(exist);
public static final Condition hidden
Opposite to appear
Sample: $("input").shouldBe(hidden);
public static final Condition appear
visible - may be used for better readability
Sample: $("#logoutLink").should(appear);
@Deprecated public static final Condition appears
visible - may be used for better readability
$("#logoutLink").waitUntil(appears, 10000);
@Deprecated public static final Condition disappears
hidden - may be used for better readability:
Sample: $("#loginLink").waitUntil(disappears, 9000);
public static final Condition disappear
hidden - may be used for better readability:
$("#loginLink").should(disappear);
public static final Condition readonly
Sample: $("input").shouldBe(readonly);
public static final Condition empty
Sample: $("#input").shouldBe(empty)
2) For other elements, check that text is empty
Sample: $("h2").shouldBe(empty)
public static final Condition image
public static final Condition focused
public static final Condition enabled
WebElement#isEnabled()public static final Condition disabled
WebElement#isEnabled()public static final Condition selected
WebElement#isSelected()public static final Condition checked
WebElement#isSelected()public Condition(java.lang.String name)
public Condition(java.lang.String name,
boolean absentElementMatchesCondition)
public static Condition attribute(java.lang.String attributeName)
Sample: $("#mydiv").shouldHave(attribute("fileId"));
attributeName - name of attribute, not nullpublic static Condition attribute(java.lang.String attributeName, java.lang.String expectedAttributeValue)
Sample: $("#mydiv").shouldHave(attribute("fileId", "12345"));
attributeName - name of attributeexpectedAttributeValue - expected value of attributepublic static Condition attributeMatching(java.lang.String attributeName, java.lang.String attributeRegex)
Sample: $("h1").should(attributeMatching("fileId", ".*12345.*"))
attributeName - name of attributeattributeRegex - regex to match attribute valuepublic static Condition href(java.lang.String href)
Sample: $("#mydiv").shouldHave(href("/one/two/three.pdf"));
href - expected value of "href" attributepublic static Condition value(java.lang.String expectedValue)
Sample: $("input").shouldHave(value("12345 666 77"));
expectedValue - expected value of "value" attributepublic static Condition pseudo(java.lang.String pseudoElementName, java.lang.String propertyName, java.lang.String expectedValue)
Sample: $("input").shouldHave(pseudo(":first-letter", "color", "#ff0000"));
pseudoElementName - pseudo-element name of the element,
":before", ":after", ":first-letter", ":first-line", ":selection"propertyName - property name of the pseudo-elementexpectedValue - expected value of the propertypublic static Condition pseudo(java.lang.String pseudoElementName, java.lang.String expectedValue)
Sample: $("input").shouldHave(pseudo(":before", "Hello"));
pseudoElementName - pseudo-element name of the element, ":before", ":after"expectedValue - expected content of the pseudo-elementpublic static Condition exactValue(java.lang.String value)
Sample: $("#input").shouldHave(exactValue("John"));
value - expected value of input fieldpublic static Condition name(java.lang.String name)
Sample: $("#input").shouldHave(name("username"))
name - expected name of input fieldpublic static Condition type(java.lang.String type)
Sample: $("#input").shouldHave(type("checkbox"))
type - expected type of input fieldpublic static Condition id(java.lang.String id)
Sample: $("#input").shouldHave(id("myForm"))
id - expected id of input field@Deprecated public static Condition matchesText(java.lang.String text)
matchText(String)Sample: $(".error_message").waitWhile(matchesText("Exception"), 12000)
matchText(String)public static Condition matchText(java.lang.String regex)
Sample: $("h1").should(matchText("Hello\s*John"))
regex - e.g. Kicked.*Chuck Norris - in this case ".*" can contain any characters including spaces, tabs, CR etc.public static Condition text(java.lang.String text)
Assert that element contains given text as a substring.
Sample: $("h1").shouldHave(text("Hello\s*John"))
NB! Case insensitive
NB! Ignores multiple whitespaces between words
text - expected text of HTML element.
NB! Empty string is not allowed (because any element does contain an empty text).java.lang.IllegalArgumentException - if given text is null or emptypublic static Condition selectedText(java.lang.String expectedText)
Sample: $("input").shouldHave(selectedText("Text"))
NB! Case sensitive
expectedText - expected selected text of the elementpublic static Condition textCaseSensitive(java.lang.String text)
Sample: $("h1").shouldHave(textCaseSensitive("Hello\s*John"))
NB! Ignores multiple whitespaces between words
text - expected text of HTML elementpublic static Condition exactText(java.lang.String text)
Sample: $("h1").shouldHave(exactText("Hello"))
Case insensitive
NB! Ignores multiple whitespaces between words
text - expected text of HTML elementpublic static Condition ownText(java.lang.String text)
Sample: $("h1").shouldHave(ownText("Hello"))
Case insensitive
NB! Ignores multiple whitespaces between words
text - expected text of HTML element without its childrenpublic static Condition exactOwnText(java.lang.String text)
Sample: $("h1").shouldHave(ownText("Hello"))
Case insensitive
NB! Ignores multiple whitespaces between words
text - expected text of HTML element without its childrenpublic static Condition exactTextCaseSensitive(java.lang.String text)
Sample: $("h1").shouldHave(exactTextCaseSensitive("Hello"))
NB! Ignores multiple whitespaces between words
text - expected text of HTML elementpublic static Condition cssClass(java.lang.String cssClass)
Sample: $("input").shouldHave(cssClass("active"));
public static Condition cssValue(java.lang.String propertyName, java.lang.String expectedValue)
Note that if css property is missing WebElement#getCssValue return empty string.
In this case you should assert against empty string.
Sample:
<input style="font-size: 12">
$("input").shouldHave(cssValue("font-size", "12"));
$("input").shouldHave(cssValue("display", "block"));
propertyName - the css property (style) name of the elementexpectedValue - expected value of css propertyWebElement#getCssValuepublic static Condition match(java.lang.String description, java.util.function.Predicate<WebElement> predicate)
Sample: $("input").should(match("empty value attribute", el -> el.getAttribute("value").isEmpty()));
description - the description of the predicatepredicate - the Predicate to matchpublic static Condition not(Condition condition)
Used for methods like $.shouldNot(exist), $.shouldNotBe(visible)
Typically you don't need to use it.
public Condition negate()
public static Condition and(java.lang.String name, Condition... conditions)
name - Name of this condition, like "empty" (meaning e.g. empty text AND empty value).conditions - Conditions to match.public static Condition or(java.lang.String name, Condition... conditions)
name - Name of this condition, like "error" (meaning e.g. "error" OR "failed").conditions - Conditions to match.public static Condition be(Condition delegate)
delegate - next condition to wrappublic static Condition have(Condition delegate)
delegate - next condition to wrappublic abstract boolean apply(Driver driver, WebElement element)
element - given WebElementpublic boolean applyNull()
public java.lang.String actualValue(Driver driver, WebElement element)
driver - given driverelement - given WebElementpublic Condition because(java.lang.String message)
public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String getName()
public boolean missingElementSatisfiesCondition()