com.vaadin.testbench.unit.
Class ComponentQuery<T extends Component>
Type Parameters:
T
- the type of the component(s) to search for
Query class used for finding a component inside a given search context.
The search context is either the current UI
instance which searches through the whole component tree, or a
Component
instance, which limits the search
to the component subtree.
See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionComponentQuery
(Class<T> componentType) Creates a new instance of
ComponentQuery
to search for components of given type. -
Method Summary
Modifier and TypeMethodDescriptionall()
Executes the search against current context and returns a list of matching components.
atIndex
(int index) Executes the search against current context and returns the component at given index.
boolean
exists()
Checks if this
ComponentQuery
describes existing components.protected T
find()
first()
Executes the search against current context and returns the first result.
Sets the context to search inside.
Executes a search for a component with the given id.
last()
Executes the search against current context and returns the last result.
single()
Executes the search against current context and returns the component, expecting to find exactly one.
<E extends Component>
ComponentQuery<E>Gets a new
ComponentQuery
to search for given component type on the context of the matching component at given index for current query.<E extends Component>
ComponentQuery<E>thenOnFirst
(Class<E> componentType) Gets a new
ComponentQuery
to search for given component type on the context of first matching component for current query.withAttribute
(String attribute) Requires the search to find components with the given attribute set, independently of its value.
withAttribute
(String attribute, String value) Requires the search to find components having the given attribute with exactly the expected value.
withCaption
(String caption) Requires the component to have a caption equal to the given text Concept of caption vary based on the component type.
withCaptionContaining
(String text) Requires the component to have a caption containing the given text Concept of caption vary based on the component type.
withClassName
(String... className) Requires the components to have all the given CSS class names
withCondition
(Predicate<T> condition) Requires the components to satisfy the given condition.
Requires the component to have the given id
withMaxResults
(int max) Requires the search to find at most the given number of components
withMinResults
(int min) Requires the search to find at least the given number of components
withoutAttribute
(String attribute) Requires the search to find components without the given attribute.
withoutAttribute
(String attribute, String value) Requires the search to find components having the given attribute value different from the provided one, or to not have the attribute at all.
withoutClassName
(String... className) Requires the components to have none of the given CSS class names
withoutTheme
(String theme) Add theme that should not be available on the target component.
<V> ComponentQuery<T>
withPropertyValue
(Function<T, V> getter, V expectedValue) Requires the given property to have expected value.
withResultsSize
(int count) Requires the search to find exactly the given number of components
withResultsSize
(int min, int max) Requires the search to find a number of components within given range
Requires the text content of the component to be equal to the given text
withTextContaining
(String text) Requires the text content of the component to contain the given text
Add theme that should be set on the target component.
<V> ComponentQuery<T>
withValue
(V expectedValue) Requires the component to be an implementation of
HasValue
interface and to have exactly the given value.
-
Constructor Details
-
ComponentQuery
Creates a new instance of
ComponentQuery
to search for components of given type.Parameters:
componentType
- the type of the component(s) to search for
-
-
Method Details
-
withPropertyValue
Requires the given property to have expected value.
Parameters:
getter
- the function to get the value of the property of the field, not nullexpectedValue
- value to be compared with the one obtained by applying the getter function to a component instanceReturns:
this element query instance for chaining
-
withValue
Requires the component to be an implementation of
HasValue
interface and to have exactly the given value. Providing a null value asexpectedValue
has no effects since the filter will not be applied.Parameters:
expectedValue
- value to be compared with the one obtained byHasValue.getValue()
Returns:
this element query instance for chaining
See Also:
-
withId
Requires the component to have the given id
Parameters:
id
- the id to look upReturns:
this element query instance for chaining
-
withCondition
Requires the components to satisfy the given condition.
Parameters:
condition
- the condition to check against the components.Returns:
this element query instance for chaining
-
withClassName
Requires the components to have all the given CSS class names
Parameters:
className
- required CSS class names, not nullReturns:
this element query instance for chaining
-
withoutClassName
Requires the components to have none of the given CSS class names
Parameters:
className
- CSS class names that component should not have, not nullReturns:
this element query instance for chaining
-
withTheme
Add theme that should be set on the target component.
Parameters:
theme
- theme that should exist on the component.Returns:
this element query instance for chaining
-
withoutTheme
Add theme that should not be available on the target component.
Parameters:
theme
- theme that should not exist on the component.Returns:
this element query instance for chaining
-
withCaption
Requires the component to have a caption equal to the given text Concept of caption vary based on the component type. The check is usually made against the
Element
label property, but for some component (e.g. Button) the text content may be used.Parameters:
caption
- the text the component is expected to have as its captionReturns:
this element query instance for chaining
-
withCaptionContaining
Requires the component to have a caption containing the given text Concept of caption vary based on the component type. The check is usually made against the
Element
label property, but for some component (e.g. Button) the text content may be used.Parameters:
text
- the text the component is expected to have as its captionReturns:
this element query instance for chaining
-
withText
Requires the text content of the component to be equal to the given text
Parameters:
text
- the text the component is expected to have as its contentReturns:
this element query instance for chaining
See Also:
-
withTextContaining
Requires the text content of the component to contain the given text
Parameters:
text
- the text the component is expected to have as its captionReturns:
this element query instance for chaining
See Also:
-
withResultsSize
Requires the search to find exactly the given number of components
Parameters:
count
- the expected number of component retrieved by the searchReturns:
this element query instance for chaining
Throws:
IllegalArgumentException
- ifcount
is negative -
withResultsSize
Requires the search to find a number of components within given range
Parameters:
min
- minimum number of components that should be found (inclusive)max
- maximum number of components that should be found (inclusive)Returns:
this element query instance for chaining
Throws:
IllegalArgumentException
- ifmin
ormax
are negative, or ifmin
is greater thanmax
-
withMinResults
Requires the search to find at least the given number of components
Parameters:
min
- minimum number of components that should be found (inclusive)Returns:
this element query instance for chaining
Throws:
IllegalArgumentException
- ifmin
ormax
are negative, or ifmin
is greater thanmax
-
withMaxResults
Requires the search to find at most the given number of components
Parameters:
max
- maximum number of components that should be found (inclusive)Returns:
this element query instance for chaining
Throws:
IllegalArgumentException
- ifmin
ormax
are negative, or ifmin
is greater thanmax
-
withAttribute
Requires the search to find components with the given attribute set, independently of its value.
Parameters:
attribute
- the name of the attribute, not nullReturns:
this element query instance for chaining
-
withAttribute
Requires the search to find components having the given attribute with exactly the expected value.
Parameters:
attribute
- the name of the attribute, not nullvalue
- value expected to be set on attribute, not nullReturns:
this element query instance for chaining
-
withoutAttribute
Requires the search to find components without the given attribute.
Parameters:
attribute
- the name of the attribute, not nullReturns:
this element query instance for chaining
-
withoutAttribute
Requires the search to find components having the given attribute value different from the provided one, or to not have the attribute at all.
Parameters:
attribute
- the name of the attribute, not nullvalue
- value expected not to be set on attribute, not nullReturns:
this element query instance for chaining
-
thenOnFirst
Gets a new
ComponentQuery
to search for given component type on the context of first matching component for current query.Type Parameters:
E
- the type of the component(s) to search forParameters:
componentType
- the type of the component(s) to search forReturns:
a new query object, to search for nested components.
Throws:
NoSuchElementException
- if first component is found -
thenOn
Gets a new
ComponentQuery
to search for given component type on the context of the matching component at given index for current query. Index is 1-based. Given a zero or negative index or an index higher than the actual number of components found results in anIndexOutOfBoundsException
.Type Parameters:
E
- the type of the component(s) to search forParameters:
componentType
- the type of the component(s) to search forReturns:
a new query object, to search for nested components.
Throws:
IllegalArgumentException
- if index is zero or negativeIndexOutOfBoundsException
- if index is greater than the number of found componentsNoSuchElementException
- if current query does not produce resultsSee Also:
-
single
Executes the search against current context and returns the component, expecting to find exactly one. Exceptions are thrown if the search produces zero or more than one result.
Returns:
the component of the type specified in the constructor.
Throws:
NoSuchElementException
- if not exactly one component is found -
first
Executes the search against current context and returns the first result.
Returns:
a component of the type specified in the constructor.
Throws:
NoSuchElementException
- if no component is found -
last
Executes the search against current context and returns the last result.
Returns:
a component of the type specified in the constructor.
Throws:
NoSuchElementException
- if no component is found -
atIndex
Executes the search against current context and returns the component at given index. Index is 1-based. Given a zero or negative index or an index higher than the actual number of components found results in an
IndexOutOfBoundsException
.Returns:
the component of the type specified in the constructor.
Throws:
IllegalArgumentException
- if index is zero or negativeIndexOutOfBoundsException
- if index is greater than the number of found componentsNoSuchElementException
- if no component is found -
id
Executes a search for a component with the given id.
Parameters:
id
- the id to look upReturns:
the component with the given id
Throws:
NoSuchElementException
- if no component is found -
exists
public boolean exists()Checks if this
ComponentQuery
describes existing components.Returns:
true if components are found, otherwise false.
-
all
Executes the search against current context and returns a list of matching components.
Returns:
a list of found components, or an empty list if search does not produce results. Never null.
-
from
Sets the context to search inside. If a null value is given, the search will be performed againt the UI.
Parameters:
context
- a component used as starting element for search.Returns:
this component query instance for chaining.
-
find
-