web-infra-dev / web-infra-dev/midscene

[Feature]: Support for Task Nesting and Conditional Execution in YAML Scripts

Open
#2,215 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
14.9k
Forks
1.2k
Avg merge
1d 14h
Merged PRs (30d)
96

Description

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

  1. Code Reusability - Define common flows once, reuse across tasks
  2. Maintainability - Update login logic in one place, all tasks benefit
  3. Expressiveness - Handle complex real-world scenarios gracefully
  4. Non-developer Friendly - Clear, readable syntax for QA/PM

Current Workaround

Users can:

  1. Duplicate steps across tasks (maintenance burden)
  2. Use JavaScript for logic (less accessible for non-developers)
  3. Build custom orchestration layer outside midscene (adds complexity)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files, tests, or entry points to begin from. First locate the YAML script parsing and task execution paths, then define and test the supported nesting and conditional syntax, including reuse, if-only, if-else, and variable-based conditions.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, yaml
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.