Introduction
TOSCA, a widely recognized automation tool from Tricentis, supports model-based testing that minimizes scripting effort and boosts reusability. Among its most valuable features are control structures like If, Do, and While loops. These constructs enable decision-making and repetition within automated test cases, allowing testers to simulate real user interactions in a more dynamic and efficient way.
This guide is dedicated to beginners looking to master Loops in TOSCA. We will go beyond the basics to explore buffer creation, logical expressions, loop flow, ScratchBook evaluations, login condition checks, and mathematical operations, all drawn from your shared screenshots and real-world test case examples from Demo Web Shop by Tricentis.
If you’re aiming to strengthen your automation foundation with the TOSCA Automation Tool for Beginners, learning Loops in TOSCA is a strategic move. These loops allow for smarter test planning, condition-driven flows, and automated decision-making without manual intervention.
Understanding If Conditions in TOSCA
Real-World Example: Login Detection on Demo Web Shop
To start, open the demo site and build logic to identify if a user is logged in. Based on the visibility of the login button, you can direct the test to either login or logout.
Steps to Implement If Condition:
- Launch the Demo Web Shop homepage.
- Add an If Condition block to your test case.
- Inside the Condition block:
- Use the Demo Web Shop Login module.
- Add a Verify step on the login button.
- Set the condition as: Visible == True.
- Then Block: Click the login button if the condition is true.
- Else Block:
- Click logout.
- Then, click login.
This ensures the user session is reset cleanly before proceeding with test steps like purchasing or checking out.
Visual Flow Explained
Your provided flowchart captures this perfectly:
- OpenURL command initiates the test.
- The If block checks if the login button is visible.
- If Yes: Log in.
- If No: Log out first, then log in again.
This type of branching logic is one of the most fundamental use cases of Loops in TOSCA.
Using Multiple Conditions in If Block
Why Use Multiple Conditions?
In real testing scenarios, decisions often rely on multiple criteria. TOSCA supports logical operators that allow complex condition combinations.
Operators You Can Use:
- AND, && → Both conditions must be true
- OR, || → At least one condition must be true
Expression Examples:
- {B[X]} <= {B[Y]} AND {B[X]} < 5
- {B[X]} <= {B[Y]} OR {B[X]} < 5
- {B[X]} <= {B[Y]} && {B[X]} < 25
- {B[X]} <= {B[Y]} || {B[X]} < 10
You can apply these in If blocks or evaluation tools to make your test cases adaptable and intelligent. These condition checks work seamlessly with Loops in TOSCA to manage flow control dynamically.
While Loop in TOSCA: Counting from 1 to 5
Objective
Use a While loop to print numbers from 1 to 5 by incrementing a buffer. This scenario is ideal for practicing Loops in TOSCA with basic math and condition evaluation.
Step-by-Step Instructions:
- Create a Buffer:
- Use TBOX Set Buffer to define a buffer called Count.
- Initial value = 0.
- Add a While Loop:
- Set the property MaximumRepetitions = 30 to prevent infinite loops.
- Add a Condition Block:
- Use TBOX Evaluation Tool
- Expression: {B[Count]} < 5
- ActionMode: Verify
- Add a Loop Block:
- Use another TBOX Set Buffer
- Expression: {MATH[{B[Count]}+1]}
Execution in ScratchBook:
- Repetition 1: 0 < 5 → True → Count = 1
- Repetition 2: 1 < 5 → True → Count = 2
- Repetition 3: 2 < 5 → True → Count = 3
- Repetition 4: 3 < 5 → True → Count = 4
- Repetition 5: 4 < 5 → True → Count = 5
- Repetition 6: 5 < 5 → False → Loop exits
This structure showcases conditional repetition, one of the core benefits of Loops in TOSCA.
Practicing such simple loops helps learners gain confidence with loop logic.
Do Loop in TOSCA: Counting from 1 to 10
Goal:
Simulate a Do loop where the loop body executes at least once, even if the condition might fail. This is particularly useful when working with retries or confirmation dialogs.
Step-by-Step Setup:
- Initialize Count:
- TBOX Set Buffer → Count = 0
- Add a While Loop (to act like Do Loop)
- Property: MaximumRepetitions = 30
- Below Condition:
- Use TBOX Evaluation Tool
- Expression: {B[Count]} <= 10
- Inside Loop:
- Increment Count: {MATH[{B[Count]}+1]}
Key Notes:
- Don’t add spaces inside {MATH[…]}.
- Always verify the condition using ActionMode: Verify.
ScratchBook Logs:
- Count = 1 → 1 <= 10 → True
- Count = 2 → 2 <= 10 → True
- …
- Count = 10 → 10 <= 10 → True
- Count = 11 → 11 <= 10 → False → Exit
Understanding this model is essential in using Loops in TOSCA for test cases that must run at least once regardless of conditions.
Do Loop to Print Numbers from 1 to 20: Advanced Version
Setup:
- TBOX Set Buffer:
- Set X = 1, Y = 20
- Do Loop Structure:
- Loop Block: {MATH[{B[X]}+1]} → increment X
- Condition Block: {B[X]} <= {B[Y]}
ScratchBook Flow:
- Repetition 1: 1 <= 20 → True
- Repetition 2: 2 <= 20 → True
- Repetition 20: 20 <= 20 → True
- Repetition 21: 21 <= 20 → False → Exit
This example clearly illustrates the power and clarity of Loops in TOSCA when working with increment logic.
ScratchBook Analysis: Validating Loop Execution
detailed ScratchBook reports:
- Each repetition is logged: Repetition 1, 2, 3…
- Conditions evaluated: 2<10, 9<10, 10<10
- Outcomes noted as ‘True’ or ‘False’
This visibility helps:
- Validate loop logic
- Ensure math expressions work as expected
- Debug failed or incomplete loops
- Understand how Loops in TOSCA unfold in real-time
Do vs While Loop in TOSCA
Feature | Do Loop | While Loop |
Order of Execution | Executes loop block first | Verifies condition first |
Use Case | At least one run is mandatory | Run only if condition is true |
Example | Print numbers, retry login | Validate button visibility first |
Practical Implication:
- Use Do Loop when a step must run before checking (e.g., clicking a button).
- Use While Loop when logic should only proceed after a check passes.
- This distinction is a core concept when practicing Loops in TOSCA efficiently.
Pro Tips for Working with Loops in TOSCA
- Always define a maximum repetition limit to avoid infinite loops.
- Use ScratchBook to debug: It gives a clear view of buffer values and evaluations.
- Use logical operators (AND, OR, &&, ||) to construct robust conditions.
- Keep math functions clean: No spaces inside {MATH[…]}.
- Reset buffers before re-running test cases.
- Design nested structures when combining If blocks within loops for complex workflows.
- Practice simple logic examples before applying Loops in TOSCA to critical test paths.
If you’re preparing for the Tricentis TOSCA Certification, understanding how to apply loops with conditions and buffers will significantly improve your automation proficiency. It is a key component of most real-world certification assignments and practical assessments.
Recommendation:
After practicing control structures like loops, conditions, and buffers, the logical next step is to advance your knowledge through structured TOSCA Online Training. These programs often cover modules, test case design strategies, reusable test steps, and integration testing techniques that go beyond what’s covered here.
Conclusion
Mastering Loops in TOSCA is crucial for building intelligent, flexible, and robust test automation scenarios. With precise buffer control, logical evaluation, and visual validation using ScratchBook, testers can model both simple and complex workflows that adapt to real-time conditions.
From detecting login states to printing dynamic values and evaluating UI visibility, these control structures elevate test design quality. Whether you’re new to TOSCA or refining your skills, practice is key. Reuse loop logic across test cases to gain consistency and efficiency.
Start exploring Loops in TOSCA today and make your automation smarter, faster, and error-proof. Practice using Loops in TOSCA regularly to master flow control. Design resilient scripts with Loops in TOSCA for real-world coverage. Don’t underestimate the value of understanding Loops in TOSCA for UI and backend testing.