How Queries and Actions work together
mainWallaby's API is built on two core concepts: Queries and Actions.
- Queries are declarative descriptions of elements you want to interact with (e.g.,
css(".user", count: 3)ortext_field("Name")). - Actions use these queries to perform operations on the DOM (e.g.,
click/2,fill_in/3).
Key Behavior: Actions will block until the query is satisfied or the action times out. This built-in blocking helps reduce race conditions when elements are added or removed dynamically by asynchronous JavaScript.
Example of combining queries and actions:
session
|> find(css(".user", count: 3))
|> List.first
|> assert_has(css(".user-name", count: 1, text: "Ada"))