wallaby v0.17.0 Wallaby.Query

Provides the query DSL.

Queries are used to locate and retrieve DOM elements from a browser (see Wallaby.Browser). You create queries like so:

Query.css(".some-css")
Query.xpath(".//input")

Form elements

There are several custom finders for locating form elements. Each of these allows finding by their name, id text, or label text. This allows for more robust querying and decouples the query from presentation selectors like css classes.

Query.text_field("My Name")
Query.checkbox("Checkbox")
Query.select("A Fancy Select Box")

Query Options

All of the query operations accept the following options:

  • :count - The number of elements that should be found (default: 1).
  • :visible - Determines if the query should return only visible elements (default: true).
  • :text - Text that should be found inside the element (default: nil).

Re-using queries

It is often convenient to re-use queries. The easiest way is to use module attributes:

@name_field Query.text_field(“User Name”) @submit_button Query.button(“Save”)

If the queries need to be dynamic then you should create a module that encapsulates the queries as functions:

defmodule TodoListPage do
  def todo_list() do
    Query.css(".todo-list")
  end

  def todos(count) do
    Query.css(".todo", count: count)
  end
end

Summary

Types

compiled()
compiled() :: {:xpath | :css, String.t}
conditions()
conditions() :: [count: non_neg_integer, text: String.t, visible: boolean, minimum: non_neg_integer]
html_validation()
html_validation() :: :bad_label | :button_type | nil
method()
method ::
  :css |
  :xpath |
  :link |
  :button |
  :fillable_field |
  :checkbox |
  :radio_button |
  :option |
  :select |
  :file_field
opts()
opts() :: [...]
result()
result() :: [Wallaby.Element.t]
selector()
selector() :: String.t
t()
t() :: %Wallaby.Query{conditions: conditions, html_validation: html_validation, method: method, result: result, selector: selector}

Functions

button(selector, opts \\ [])
checkbox(selector, opts \\ [])
compile(map)
compile(t) :: compiled
count(query)
css(selector, opts \\ [])
file_field(selector, opts \\ [])
fillable_field(selector, opts \\ [])
inner_text(query)
link(selector, opts \\ [])
matches_count?(map, count)
option(selector, opts \\ [])
radio_button(selector, opts \\ [])
result(query)
select(selector, opts \\ [])
text(selector, opts \\ [])
text_field(selector, opts \\ [])
validate(query)
visible?(query)
xpath(selector, opts \\ [])