Control Flow in YAML Tests
This guide covers conditional logic (if blocks) and loops (while blocks) in Revyl YAML tests.If Blocks - Conditional Branching
If blocks allow you to execute different test paths based on conditions. They’re evaluated by AI, so you can use natural language conditions.Basic Structure
Copy
Ask AI
- type: if
condition: "natural language condition"
then:
- # blocks executed when condition is true
else: # optional
- # blocks executed when condition is false
Simple If Block
Execute actions only when a condition is met:Copy
Ask AI
test:
metadata:
name: "Cookie Banner Handling"
platform: web
build:
name: "Website"
blocks:
# Test starts at build URL automatically
- type: if
condition: "A cookie consent banner is visible"
then:
- type: instructions
step_description: "Click 'Accept All'"
- type: instructions
step_description: "Click 'Get Started'"
If-Else Block
Handle both true and false cases:Copy
Ask AI
test:
metadata:
name: "Login State Check"
platform: web
build:
name: "App"
blocks:
- type: if
condition: "The user is already logged in"
then:
- type: validation
step_description: "Dashboard is visible"
- type: instructions
step_description: "Click profile menu"
else:
- type: instructions
step_description: "Enter '[email protected]' in email"
- type: instructions
step_description: "Enter 'password' in password field"
- type: instructions
step_description: "Click login"
- type: validation
step_description: "Dashboard is now visible"
Nested If Blocks
Complex conditional logic with multiple levels:Copy
Ask AI
test:
metadata:
name: "Payment Method Selection"
platform: web
build:
name: "Checkout App"
blocks:
- type: instructions
step_description: "Proceed to payment page"
- type: if
condition: "A saved payment method exists"
then:
- type: validation
step_description: "Saved payment option is shown"
- type: instructions
step_description: "Select the saved payment method"
else:
- type: instructions
step_description: "Click 'Add New Payment Method'"
- type: if
condition: "Apple Pay is available"
then:
- type: instructions
step_description: "Select Apple Pay"
- type: instructions
step_description: "Complete Apple Pay authorization"
else:
- type: instructions
step_description: "Enter credit card number"
- type: instructions
step_description: "Enter expiry date and CVV"
- type: instructions
step_description: "Complete payment"
If Blocks with Variables
Use variables in conditions:Copy
Ask AI
test:
metadata:
name: "Discount Code Application"
platform: web
build:
name: "Shopping Site"
blocks:
- type: extraction
step_description: "The cart total"
variable_name: cart-total
- type: if
condition: "The cart total is greater than $100"
then:
- type: validation
step_description: "Free shipping banner is visible"
- type: if
condition: "A discount code field is present"
then:
- type: instructions
step_description: "Enter 'SAVE20' in discount code"
- type: instructions
step_description: "Click 'Apply'"
else:
- type: validation
step_description: "Shipping charges apply message is shown"
Multiple Conditions in Sequence
Chain multiple if blocks for different conditions:Copy
Ask AI
test:
metadata:
name: "Feature Availability Check"
platform: web
build:
name: "SaaS App"
blocks:
- type: instructions
step_description: "Navigate to features page"
- type: if
condition: "Dark mode toggle is available"
then:
- type: instructions
step_description: "Enable dark mode"
- type: if
condition: "Beta features section is visible"
then:
- type: instructions
step_description: "Enable experimental features"
- type: if
condition: "A feedback button is present"
then:
- type: instructions
step_description: "Click feedback button"
- type: instructions
step_description: "Enter 'Great app!' in feedback field"
- type: instructions
step_description: "Submit feedback"
While Blocks - Loops
While blocks repeat a set of actions until a condition becomes false. They’re useful for pagination, infinite scroll, and iterative actions.Basic Structure
Copy
Ask AI
- type: while
condition: "continue while this is true"
body:
- # blocks executed each iteration
Simple While Loop
Load all paginated content:Copy
Ask AI
test:
metadata:
name: "Load All Products"
platform: web
build:
name: "E-commerce Site"
blocks:
- type: instructions
step_description: "Navigate to products catalog"
- type: while
condition: "A 'Load More' button is visible"
body:
- type: instructions
step_description: "Click 'Load More'"
- type: manual
step_type: wait
step_description: "2"
- type: validation
step_description: "All products are loaded"
While Loop with Conditional Exit
Loop with additional exit condition:Copy
Ask AI
test:
metadata:
name: "Load Until Limit"
platform: web
build:
name: "Data Dashboard"
blocks:
- type: instructions
step_description: "Navigate to reports section"
- type: while
condition: "More data button exists and error message is not shown"
body:
- type: instructions
step_description: "Click 'Load More Data'"
- type: if
condition: "A rate limit error is displayed"
then:
- type: validation
step_description: "Rate limit reached message is shown"
- type: validation
step_description: "All available data is loaded or rate limit reached"
Dismissing Multiple Items
Remove items in a loop:Copy
Ask AI
test:
metadata:
name: "Clear All Notifications"
platform: ios
build:
name: "Social App"
blocks:
- type: instructions
step_description: "Open notifications"
- type: while
condition: "Notification items are present"
body:
- type: instructions
step_description: "Swipe left on the first notification"
- type: instructions
step_description: "Tap 'Delete'"
- type: validation
step_description: "No notifications remain"
- type: validation
step_description: "Empty state message is shown"
Combined Patterns
If Inside While
Conditional logic within a loop:Copy
Ask AI
test:
metadata:
name: "Process Items with Conditions"
platform: web
build:
name: "Task Manager"
blocks:
- type: instructions
step_description: "Open pending tasks list"
- type: while
condition: "Pending tasks are visible"
body:
- type: extraction
step_description: "The first task name"
variable_name: task-name
- type: if
condition: "Task '$task-name$' is marked as priority"
then:
- type: instructions
step_description: "Click 'Complete Now' for task '$task-name$'"
else:
- type: instructions
step_description: "Click 'Skip' for task '$task-name$'"
- type: validation
step_description: "All tasks have been processed"
While Inside If
Loop only when condition is met:Copy
Ask AI
test:
metadata:
name: "Conditional Infinite Scroll"
platform: web
build:
name: "News Site"
blocks:
- type: instructions
step_description: "Navigate to articles"
- type: if
condition: "Premium member badge is displayed"
then:
- type: validation
step_description: "Access to all content is available"
- type: while
condition: "More articles button is visible"
body:
- type: instructions
step_description: "Click 'Load More Articles'"
else:
- type: validation
step_description: "Free tier content limit message is shown"
- type: validation
step_description: "All accessible articles are loaded"
Nested While Loops
Multiple levels of iteration:Copy
Ask AI
test:
metadata:
name: "Multi-Level Navigation"
platform: web
build:
name: "Documentation Site"
blocks:
- type: instructions
step_description: "Open documentation sidebar"
- type: while
condition: "More documentation sections are available"
body:
- type: extraction
step_description: "Current section name"
variable_name: section-name
- type: instructions
step_description: "Expand section '$section-name$'"
- type: while
condition: "Subsections are visible in '$section-name$'"
body:
- type: extraction
step_description: "First subsection name"
variable_name: subsection-name
- type: instructions
step_description: "Click subsection '$subsection-name$'"
- type: validation
step_description: "Content for '$subsection-name$' is displayed"
- type: instructions
step_description: "Return to section list"
- type: instructions
step_description: "Collapse section '$section-name$'"
- type: validation
step_description: "All sections have been explored"
Sequential Conditions with Loop
Multiple if blocks followed by a loop:Copy
Ask AI
test:
metadata:
name: "Feature Tour with Optional Steps"
platform: ios
build:
name: "Productivity App"
blocks:
- type: if
condition: "Welcome tour prompt is shown"
then:
- type: instructions
step_description: "Tap 'Start Tour'"
- type: if
condition: "Permissions request is displayed"
then:
- type: instructions
step_description: "Tap 'Allow'"
- type: if
condition: "Notification preferences screen is shown"
then:
- type: instructions
step_description: "Select notification preferences"
- type: instructions
step_description: "Tap 'Continue'"
- type: while
condition: "Tour has more steps"
body:
- type: instructions
step_description: "Tap 'Next'"
- type: manual
step_type: wait
step_description: "1"
- type: validation
step_description: "Tour is complete and main screen is visible"
Best Practices
1. Keep Conditions Simple and Clear
Copy
Ask AI
# GOOD - clear condition
- type: if
condition: "Login button is visible"
then:
- type: instructions
step_description: "Click login"
# AVOID - overly complex condition
- type: if
condition: "Login button is visible and enabled and not grayed out and the form is complete"
then:
- type: instructions
step_description: "Click login"
2. Avoid Deeply Nested Control Flow
Copy
Ask AI
# GOOD - flat structure with sequential checks
- type: if
condition: "Feature A is available"
then:
- type: instructions
step_description: "Enable feature A"
- type: if
condition: "Feature B is available"
then:
- type: instructions
step_description: "Enable feature B"
# AVOID - deeply nested
- type: if
condition: "Feature A is available"
then:
- type: if
condition: "Feature B is available"
then:
- type: if
condition: "Feature C is available"
then:
- type: instructions
step_description: "Enable all features"
3. Handle Both True and False Cases
Copy
Ask AI
# GOOD - handles both cases explicitly
- type: if
condition: "User is logged in"
then:
- type: validation
step_description: "Dashboard is visible"
else:
- type: validation
step_description: "Login page is visible"
# OKAY - else not always needed
- type: if
condition: "Cookie banner is shown"
then:
- type: instructions
step_description: "Dismiss banner"
# Test continues regardless
Common Patterns
Pattern: Optional Element Handling
Handle elements that may or may not appear:Copy
Ask AI
- type: if
condition: "Modal dialog is visible"
then:
- type: instructions
step_description: "Close modal"
- type: instructions
step_description: "Continue with main flow"
Pattern: Pagination
Load all pages of content:Copy
Ask AI
- type: while
condition: "Next page button is enabled"
body:
- type: instructions
step_description: "Click next page"
Pattern: Feature Detection
Different actions based on available features:Copy
Ask AI
- type: if
condition: "Advanced mode toggle is present"
then:
- type: instructions
step_description: "Enable advanced mode"
- type: instructions
step_description: "Configure advanced settings"
else:
- type: instructions
step_description: "Use basic configuration"
Pattern: Iterative Form Filling
Fill dynamic form fields:Copy
Ask AI
- type: while
condition: "Add another item button is visible"
body:
- type: instructions
step_description: "Click add item"
- type: instructions
step_description: "Fill in item details"
- type: if
condition: "Item count is 3 or more"
then:
- type: validation
step_description: "Enough items added"
Related Documentation
- YAML Schema Reference - Complete schema documentation
- YAML Examples - More practical examples
- Using Variables - Variable management