Writing Maintainable YAML Tests with Variables and Templates
Updated on April 14, 2026
Updated on April 14, 2026
Fast-moving product teams tend to hit the same testing wall at the same time: the suite grows, UI changes accelerate, and the “simple” end-to-end checks turn into a pile of duplicated steps that are expensive to update. YAML-based tests are one of the most practical ways to prevent that outcome, because they let you express intent in a readable format while keeping structure, reuse, and version control first-class.
Shiplight AI supports a YAML-based test format designed for modular composition, including variables and templates you can reuse across flows. Combined with Shiplight’s intent-based execution and self-healing behavior, this gives teams a way to scale coverage without turning test maintenance into a second engineering backlog.
This guide focuses on how to structure YAML tests so they stay readable, reusable, and stable as your UI evolves.
A good test is both:
YAML hits that sweet spot. It encourages declarative structure (what you want to verify) while still allowing you to add parameters (variables) and reuse patterns (templates). The result is a suite that behaves more like a library of verified user behaviors than a collection of one-off scripts.
In Shiplight, this pairs naturally with AI-native workflows: you can generate tests quickly, then refactor recurring sequences into templates that become your team’s shared testing vocabulary.
Variables are the simplest way to remove duplication and keep tests environment-aware. Use them for values that change across:
The exact keys and schema vary by implementation, so treat the YAML below as an illustrative pattern, not a strict contract. The idea is to separate “what the test does” from “the data it uses.”
# Example structure (illustrative)
name: Checkout succeeds for a standard customer
vars:
baseUrl: ${ENV.BASE_URL}
userEmail: ${ENV.STANDARD_USER_EMAIL}
userPassword: ${SECRET.STANDARD_USER_PASSWORD}
sku: "starter-plan-annual"
steps:
- goTo: "${baseUrl}/login"
- fill:
field: "Email"
value: "${userEmail}"
- fill:
field: "Password"
value: "${userPassword}"
- click: "Sign in"
- goTo: "${baseUrl}/pricing"
- click: "Choose ${sku}"
- assert:
containsText: "Order confirmed"
What this buys you:
Variables can also create chaos if they are treated like a dumping ground. Three guardrails help:
Templates are how you avoid rewriting the same login flow, onboarding path, or checkout sequence dozens of times. The best templates behave like product primitives:
A good template is small, parameterized, and named after user intent, not page structure.
As you refactor, split steps into three layers:
This separation keeps templates stable even when individual tests change.
Again, treat this as a conceptual example. Your Shiplight YAML may name these fields differently, but the pattern holds.
# Example template (illustrative)
templates:
login:
params:
- email
- password
steps:
- goTo: "${vars.baseUrl}/login"
- fill: { field: "Email", value: "${email}" }
- fill: { field: "Password", value: "${password}" }
- click: "Sign in"
- assert: { containsText: "Welcome" }
Then a test can call it with different inputs:
# Example usage (illustrative)
name: Admin can access billing settings
vars:
baseUrl: ${ENV.BASE_URL}
steps:
- use: login
with:
email: ${ENV.ADMIN_EMAIL}
password: ${SECRET.ADMIN_PASSWORD}
- goTo: "${vars.baseUrl}/settings/billing"
- assert:
containsText: "Billing"
The “use template” approach is more than convenience. It is what makes your suite adaptable when your UI changes, because you update the shared template once instead of patching 40 tests.
Templates can become their own maintenance problem if they are too clever. Two rules keep them healthy:
A helpful litmus test is review speed: if a teammate can review a PR test change in under a minute and explain what user behavior is protected, your abstraction level is probably right.
YAML structure is only half the story. The hard part of UI testing is keeping tests durable as the interface evolves. This is where Shiplight AI’s platform approach matters:
The net effect is that YAML becomes a living spec for critical flows, not a fragile artifact you avoid touching.
If you want a practical starting point, use this progression:
The most effective YAML suites feel less like “automation” and more like a set of executable acceptance criteria. Variables keep scenarios portable and safe. Templates keep coverage expanding without duplication. And when those tests run on a platform built for AI-native QA, you get the speed benefits of generation without the long-term cost of brittle maintenance.
If you are already writing Shiplight tests in YAML, the fastest win is usually template refactoring. If you are not, the fastest win is simply moving your first critical flow into a readable, version-controlled format your whole team can review.
Shiplight AI is built to make that transition painless, and to keep your tests aligned with what users actually do, even when the UI refuses to sit still.