midscene.js provides a powerful YAML-based automation script format that allows defining test scenarios in a declarative way. However, when building complex test suites, we encountered scenarios where the current YAML syntax falls short.
Feature 1: Task Nesting / Task Reuse
Problem:
Currently, there's no way to call one task from another. This leads to code duplication when the same sequence of actions needs to be performed in multiple tasks.
Example use case:
A "Login" task needs to be called before many other tasks. Without task nesting, the login steps must be duplicated in every task that requires authentication.
Proposed syntax:
tasks:
- name: Login
flow:
- aiTap: username input field
- aiInput:
value: testuser
- aiTap: password input field
- aiInput:
value: password123
- aiTap: login button
- name: Search Train
flow:
- callTask: Login # nested call to Login task
- aiTap: search button
# ... other steps
- name: Book Train
flow:
- callTask: Login # reuse Login task
- aiTap: book button
# ... other steps
Alternative syntax options:
# Option A: callTask (recommended - concise and explicit)
- callTask: Login
# Option B: include (familiar to template engine users)
- include: Login
Feature 2: Conditional Execution
Problem:
There's no way to conditionally execute steps based on runtime conditions (e.g., page state, assertion results, variable values).
Example use case:
- If a popup appears, dismiss it
- If already logged in, skip the login flow
- Handle different app states based on what's visible
Proposed syntax:
tasks:
- name: Handle Login State
flow:
# Conditional: if-else based on assertion
- if:
condition:
aiAssert: login button is visible on current page
then:
- aiTap: login button
# ... login flow
else:
- aiAction: already logged in, continue with operations
# Conditional: if-only (skip if condition not met)
- if:
condition:
aiAssert: popup ad is visible
then:
- aiTap: close ad button
# Conditional: based on variable
- if:
condition: ${isLoggedIn} == false
then:
- callTask: Login
Benefits
- Code Reusability - Define common flows once, reuse across tasks
- Maintainability - Update login logic in one place, all tasks benefit
- Expressiveness - Handle complex real-world scenarios gracefully
- Non-developer Friendly - Clear, readable syntax for QA/PM
Current Workaround
Users can:
- Duplicate steps across tasks (maintenance burden)
- Use JavaScript for logic (less accessible for non-developers)
- Build custom orchestration layer outside midscene (adds complexity)
midscene.js provides a powerful YAML-based automation script format that allows defining test scenarios in a declarative way. However, when building complex test suites, we encountered scenarios where the current YAML syntax falls short.
Feature 1: Task Nesting / Task Reuse
Problem:
Currently, there's no way to call one task from another. This leads to code duplication when the same sequence of actions needs to be performed in multiple tasks.
Example use case:
A "Login" task needs to be called before many other tasks. Without task nesting, the login steps must be duplicated in every task that requires authentication.
Proposed syntax:
Alternative syntax options:
Feature 2: Conditional Execution
Problem:
There's no way to conditionally execute steps based on runtime conditions (e.g., page state, assertion results, variable values).
Example use case:
Proposed syntax:
Benefits
Current Workaround
Users can: