Skip to contents

elem_expect_all() and elem_wait_until_all() are complements to elem_expect() and elem_wait_until() that test conditions on multiple elements in an element collection.

Usage

elem_expect_all(x, ..., testthat = NULL, timeout = NULL)

elem_wait_until_all(x, ..., timeout = NULL)

Arguments

x

A selenider_elements() object.

...

<dynamic-dots> Function calls or functions that must return a logical value. If multiple conditions are given, they must all be TRUE for the test to pass. See elem_expect() for more details.

testthat

Whether to treat the expectation as a testthat test. You do not need to explicitly provide this most of the time, since by default, we can use testthat::is_testing() to figure out whether elem_expect() is being called from within a testthat test.

timeout

The number of seconds to wait for a condition to pass. If not specified, the timeout used for x will be used, or the timeout of the local session if an element is not given.

Value

elem_expect_all() returns x, invisibly.

elem_wait_until_all() returns a boolean flag: TRUE if the test passes, FALSE otherwise.

Details

If x does not contain any elements, elem_expect_all() and elem_wait_until_all() will succeed. You may want to first verify that at least one element exists with has_at_least().

elem_expect_all() and elem_wait_until_all() can be thought of as alternatives to the use of all(vapply(FUN.VALUE = logical(1))) (or purrr::every()) within elem_expect() and elem_wait_until().

For example, the following two expressions are equivalent (where x is an element collection).

elem_expect(
  x,
  \(element) all(vapply(as.list(element), is_present, logical(1)))
)
elem_expect_all(x, is_present)

However, the second example will give a more detailed error message on failure.

See also

Examples

html <- "
<div id='div1'>Content 1</div>
<div id='div2'>Content 2</div>
<div id='div3' style='display:none;'>Content 3</div>
<div id='div4'>Content 4</div>
"

session <- minimal_selenider_session(html)

ss("div") |>
  elem_expect_all(is_visible, timeout = 0.1) |>
  try()

ss("div")[-3] |>
  elem_expect_all(is_visible)