Skip to content

Modifiers

Modifiers provide additional configuration for actions and Within blocks. They are key-value pairs that customize behavior, specify selectors, or set timeouts.

Syntax Forms

Vanya supports two equivalent syntaxes for modifiers.

Parentheses Syntax

Place modifiers in parentheses directly after the action or block name:

Within the Browser (plugin: playwright-python, type: browser)
click button (timeout: 5000)
go to "/login" (timeout: 30000)

Multiple modifiers are separated by commas:

Within the Login Form (type: element, id: 'login_form', class: 'auth')
type "hello" into email-input (timeout: 5000)

With Syntax

For inline modifier lists, use with:

click button with timeout: 5000
go to "/login" with timeout: 30000

Multiple modifiers with with are also comma-separated:

wait for div with timeout: 5000, state: visible

Both syntaxes are equivalent. Patterns with indented blocks (via returns) must use parentheses syntax.

Modifier Values

Modifier values can be quoted strings or unquoted identifiers:

# Quoted values
click button (id: 'submit_btn')
click button (id: "submit_btn")
# Unquoted values
Within the Browser (plugin: playwright-python, type: browser)

The plugin defines whether each modifier expects a quoted or unquoted value type.

Reserved Modifiers

Two modifiers are handled by vanya core and are not passed to plugins:

ModifierDescriptionRequired
pluginSelects the plugin (e.g., playwright-python)Required at root Within block; inherited by nested blocks
typeSelects the type within the plugin (e.g., browser, element, api)Always required on Within blocks
Within the Browser (plugin: playwright-python, type: browser)
# Nested block inherits plugin, must specify type
Within the Form (type: element, id: 'login')
click submit-button

Plugin-Defined Modifiers

All other modifiers are defined by plugins. Each type and pattern declares its valid modifier keys in the plugin TOML file.

Type Modifiers

Types can declare modifiers that apply to Within blocks of that type:

# browser type supports: url, headless
Within the Browser (plugin: playwright-python, type: browser, url: 'http://localhost:3000')
# element type supports: id, class, testid, label
Within the Form (type: element, id: 'login_form')
# api type supports: base, timeout, headers
Within the API (plugin: python-requests, type: api, base: 'http://api.local')

Pattern Modifiers

Patterns declare modifiers that apply to specific actions:

# click pattern supports: timeout
click button (timeout: 5000)
# wait-for pattern supports: timeout, state
wait for div (timeout: 10000, state: visible)
# see pattern supports: text
see a span (text: 'Welcome')
# expect-failure pattern supports: error, capture
expect failure (error: 'TimeoutError', capture: 'exc_info')
click button (testid: 'missing')

Modifier Precedence

When both the type and pattern define the same modifier key, the pattern takes precedence. The valid modifiers for an action are the union of type modifiers and pattern modifiers.

Available Modifiers by Plugin

playwright-python

browser type

ModifierTypeDescription
urlquotedInitial URL to navigate to
headlessquotedRun browser in headless mode

element type

ModifierTypeDescription
idquotedHTML id attribute selector
classquotedCSS class selector
testidquoteddata-testid attribute selector
labelquotedAccessible label selector

Pattern modifiers

PatternModifierTypeDescription
go totimeoutquotedNavigation timeout in ms
clicktimeoutquotedClick timeout in ms
type ... intotimeoutquotedInput timeout in ms
seetextquotedText content to match
wait fortimeoutquotedWait timeout in ms
wait forstatequotedWait condition (e.g., visible)
expect failureerrorquotedException type to expect
expect failurecapturequotedVariable name to capture exception

python-requests

api type

ModifierTypeDescription
basequotedBase URL for API requests
timeoutquotedRequest timeout in ms
headersquotedHTTP headers

Pattern modifiers

PatternModifierTypeDescription
GETheadersquotedRequest headers
GETtimeoutquotedRequest timeout
POSTheadersquotedRequest headers
POSTtimeoutquotedRequest timeout
PUTheadersquotedRequest headers
PUTtimeoutquotedRequest timeout
DELETEheadersquotedRequest headers
DELETEtimeoutquotedRequest timeout
expect failureerrorquotedException type to expect
expect failurecapturequotedVariable name to capture exception

Validation

Using an unknown modifier key is a validation error. The vanya check command validates that:

  1. All modifier keys are declared by the plugin type or pattern
  2. Modifier values match the expected type (quoted or unquoted)
  3. Required modifiers (plugin, type) are present where needed
Terminal window
vanya check tests/*.vanya

Examples

Browser Testing with Modifiers

Vanya test scenario (vanya-lang.org/v0.1)
Script title: "login_with_modifiers"
Within the Browser (plugin: playwright-python, type: browser, url: 'http://localhost:3000')
go to "/login" (timeout: 30000)
Within the Login Form (type: element, id: 'login_form')
type "user@example.com" into email-input (timeout: 5000)
click submit-button (timeout: 5000)
see a div (text: 'Hello')
wait for div (timeout: 10000, state: visible)

API Testing with Modifiers

Vanya test scenario (vanya-lang.org/v0.1)
Script title: "api_with_modifiers"
Within the API (plugin: python-requests, type: api, base: 'http://api.local', timeout: 30000)
GET "/users" (headers: 'Authorization: Bearer token')
expect status 200
POST "/users" body '{"name": "alice"}' (timeout: 5000)
expect status 201

Expected Failure with Captured Exception

Within the Browser (plugin: playwright-python, type: browser)
expect failure (error: 'TimeoutError', capture: 'exc_info')
click button (testid: 'does-not-exist', timeout: 1000)