-
Notifications
You must be signed in to change notification settings - Fork 15
Variables Management
ChelSlava edited this page Apr 3, 2026
·
1 revision
RPAForge provides a comprehensive variable management system with global and local scopes, integrated with Robot Framework's variable system.
┌─────────────────────────────────────────────┐
│ Global Variables │
│ (Suite Level - Project Wide) │
│ • Available everywhere │
│ • Defined in *** Variables *** section │
│ • Can be imported from external files │
└─────────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────┐
│ Local Variables │
│ (Task/Keyword Level - Current Flow) │
│ • Available only within current diagram │
│ • Created during execution │
│ • Cleared when diagram completes │
└─────────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────┐
│ Parameter Variables │
│ (Arguments - Sub-Diagram Input) │
│ • Passed into sub-diagrams │
│ • Defined in keyword signature │
│ • Local to that execution │
└─────────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────┐
│ Return Variables │
│ (Output - Sub-Diagram Result) │
│ • Output from sub-diagrams │
│ • Assigned to caller's scope │
│ • Can be renamed by caller │
└─────────────────────────────────────────────┘
| Prefix | Name | Example | Description |
|---|---|---|---|
${} |
Scalar | ${username} |
Single value (string, number, object) |
@{} |
List | @{users} |
List/array of values |
&{} |
Dictionary | &{config} |
Key-value mapping |
%{} |
Environment | %{HOME} |
System environment variable |
type VariableType =
| 'string' // Default - any text value
| 'integer' // Whole numbers
| 'float' // Decimal numbers
| 'boolean' // True/False (RF: ${True}/${False})
| 'list' // Array of values
| 'dictionary' // Object/Map
| 'path' // File system path
| 'json' // JSON object
| 'xml' // XML document
| 'secret'; // Encrypted credentialGlobal variables are defined at the project level and available to all diagrams.
*** Variables ***
${URL} https://example.com
${BROWSER} chrome
${TIMEOUT} 30
@{CREDENTIALS} user1 user2 user3
&{CONFIG} api_endpoint=/api/v1 retry_count=3┌─────────────────────────────────────┐
│ 🌐 Global Variables │
├─────────────────────────────────────┤
│ 📝 ${URL} = "https://example.com" │
│ 📝 ${BROWSER} = "chrome" │
│ 📝 ${TIMEOUT} = 30 │
│ 📋 @{CREDENTIALS} = [user1, ...] │
│ 📖 &{CONFIG} = {api_endpoint: ...} │
│ │
│ [+ Add Variable] │
└─────────────────────────────────────┘
- Naming: Use UPPER_CASE for constants
- Grouping: Group related variables
- Documentation: Add descriptions
- External Files: Use variable files for large sets
# variables.py
"""Project-wide configuration variables."""
# URLs
URL = "https://example.com"
API_URL = "https://api.example.com"
# Browser Settings
BROWSER = "chrome"
HEADLESS = False
TIMEOUT = 30
# Test Data
CREDENTIALS = ["user1", "user2", "user3"]
CONFIG = {
"api_endpoint": "/api/v1",
"retry_count": 3,
"screenshot_dir": "screenshots"
}Local variables exist only within the current diagram execution.
*** Keywords ***
Process User Data
[Arguments] ${user_id}
${user_data}= Get User ${user_id} # Local variable
${processed}= Transform Data ${user_data}
Log ${processed} # Available here
[Return] ${processed}
# ${user_data} and ${processed} not available here- Created when first assigned
- Available in current diagram only
- Not visible to sub-diagrams (unless passed as parameter)
- Cleared when diagram completes
┌─────────────────────────────────────┐
│ 📝 Assign Variable │
├─────────────────────────────────────┤
│ ${result} = │
│ ┌─────────────────────────────────┐ │
│ │ ${value1} + ${value2} │ │
│ └─────────────────────────────────┘ │
│ │
│ Type: [String ▼] │
│ Scope: [Local ▼] │
└─────────────────────────────────────┘
| Keyword | Scope | Description |
|---|---|---|
Set Variable |
Current | Create local variable |
Set Local Variable |
Current | Explicit local scope |
Set Suite Variable |
Suite | Make available globally |
Set Global Variable |
Global | Make available everywhere |
Set Test Variable |
Test | Available in current test |
Parameters are input variables for sub-diagrams.
*** Keywords ***
Login Flow
[Arguments] ${username} ${password} ${url}=${URL}
# Use parameters
Open Browser ${url}
Input Text id=username ${username}
Input Text id=password ${password}
[Return] ${True}┌─────────────────────────────────────────┐
│ Sub-Diagram: Login Flow │
├─────────────────────────────────────────┤
│ 📥 Parameters │
│ │
│ ┌─────────────────────────────────────┐ │
│ │ Name Type Default │ │
│ │ username String (none) │ │
│ │ password Secret (none) │ │
│ │ url String ${URL} │ │
│ └─────────────────────────────────────┘ │
│ │
│ [+ Add Parameter] │
└─────────────────────────────────────────┘
When calling a sub-diagram:
┌─────────────────────────────────────┐
│ 📞 Call: Login Flow │
├─────────────────────────────────────┤
│ username: ${user} │
│ password: ${pass} │
│ url: ${LOGIN_URL} │
│ │
│ Returns: │
│ success → ${login_ok} │
└─────────────────────────────────────┘
Return variables are outputs from sub-diagrams.
*** Keywords ***
Get User Data
[Arguments] ${user_id}
${user}= Query Database SELECT * FROM users WHERE id=${user_id}
${name}= Set Variable ${user}[name]
${email}= Set Variable ${user}[email]
[Return] ${name} ${email} # Multiple return values┌─────────────────────────────────────────┐
│ Sub-Diagram: Get User Data │
├─────────────────────────────────────────┤
│ 📤 Return Values │
│ │
│ ┌─────────────────────────────────────┐ │
│ │ Variable Type Description│ │
│ │ name String User name │ │
│ │ email String User email │ │
│ └─────────────────────────────────────┘ │
└─────────────────────────────────────────┘
${user_name} ${user_email}= Get User Data ${user_id}Secrets are encrypted variables for sensitive data (passwords, API keys).
┌─────────────────────────────────────┐
│ Add Secret Variable │
├─────────────────────────────────────┤
│ Name: │
│ [password ] │
│ │
│ Value: │
│ [•••••••••• ] [👁] │
│ │
│ ☑ Encrypt and store securely │
│ │
│ [Generate] [Import] [Save] [Cancel]│
└─────────────────────────────────────┘
Secrets are stored in encrypted files:
project/
├── secrets/
│ ├── default.enc # Encrypted secrets
│ └── .gitignore # Never commit secrets
└── rpaforge.json
*** Settings ***
Library RPAForge.Credentials
*** Variables ***
${PASSWORD} %{RPAFORGE_SECRET_password} # From environment
*** Keywords ***
Login
${password}= Get Secret password
Input Text id=password ${password}┌─────────────────────────────────────┐
│ Edit Variable │
├─────────────────────────────────────┤
│ Name: │
│ [api_endpoint ] │
│ │
│ Scope: │
│ ○ Global (Suite) │
│ ● Local (Task/Keyword) │
│ ○ Parameter │
│ │
│ Type: │
│ [String ▼] │
│ │
│ Value: │
│ ┌─────────────────────────────────┐ │
│ │ /api/v1 │ │
│ └─────────────────────────────────┘ │
│ │
│ Description: │
│ ┌─────────────────────────────────┐ │
│ │ API endpoint for the service │ │
│ └─────────────────────────────────┘ │
│ │
│ [Save] [Cancel] │
└─────────────────────────────────────┘
Built into assignment blocks with autocomplete:
┌─────────────────────────────────────────────────┐
│ ${result} = │
│ ┌─────────────────────────────────────────────┐ │
│ │ ${base_url}/api/${endpoint}?id=${id} │ │
│ └─────────────────────────────────────────────┘ │
│ │
│ Available: │
│ • ${base_url} - "https://example.com" │
│ • ${endpoint} - "users" │
│ • ${id} - 123 │
│ │
│ Preview: "https://example.com/api/users?id=123"│
└─────────────────────────────────────────────────┘
# String concatenation
${full_name}= Set Variable ${first} ${last}
# Arithmetic
${total}= Evaluate ${price} * ${quantity}
# Boolean
${is_valid}= Evaluate ${age} >= 18
# List operations
@{sorted}= Sort List ${items}
# Dictionary operations
${value}= Set Variable ${config}[api_key]
# Environment
${home}= Get Environment Variable HOMEWhen debugging, inspect current variable state:
┌─────────────────────────────────────┐
│ Variable Inspector [×] │
├─────────────────────────────────────┤
│ Execution paused at: │
│ Line 15: Click Element │
├─────────────────────────────────────┤
│ 🌐 Global │
│ ${URL} = "https://example.com" │
│ ${BROWSER} = "chrome" │
│ ${TIMEOUT} = 30 │
│ │
│ 📍 Local │
│ ${username} = "admin" │
│ ${counter} = 3 │
│ @{elements} = ['btn1', 'btn2'] │
│ &{user} = {name: 'John', ...} │
│ │
│ 📥 Parameters │
│ ${input_file} = "data.xlsx" │
│ ${mode} = "update" │
│ │
│ [Refresh] [Copy All] [Export] │
└─────────────────────────────────────┘
# ✓ Good - Descriptive, snake_case
${user_name}
${max_retry_count}
${API_BASE_URL} # Constants in UPPER_CASE
@{user_list} # List with singular item name
&{config_data} # Dictionary with descriptive name
# ✗ Bad - Unclear, wrong style
${x} # Too short
${userName} # camelCase (use snake_case)
${data} # Too generic
${var1} # Numbered variables| Scope | Use Case | Example |
|---|---|---|
| Global | Configuration, URLs, constants |
${URL}, ${TIMEOUT}
|
| Local | Loop counters, temp results |
${counter}, ${result}
|
| Parameter | Sub-diagram inputs |
${user_id}, ${file_path}
|
| Return | Sub-diagram outputs |
${success}, ${data}
|
# String (default)
${name}= Set Variable John Doe
# Integer
${count}= Convert To Integer 10
# Float
${price}= Convert To Number 19.99
# Boolean
${is_ready}= Set Variable If ${count} > 0 ${True} ${False}
# List
@{items}= Create List item1 item2 item3
# Dictionary
&{user}= Create Dictionary name=John age=30
# Environment
${home}= Get Environment Variable HOME
# JSON
${data}= Evaluate json.loads('''{"key": "value"}''') json- Never hardcode secrets - Use secret variables
- Use environment variables for deployment-specific values
- Encrypt sensitive data - Use Credentials library
- Don't log secrets - Mask in output
- Use .gitignore - Exclude secret files
# ✓ Good
${password}= Get Secret password
Log Password: ****** # Masked
# ✗ Bad
${password}= Set Variable MyP@ssw0rd # Hardcoded!
Log Password: ${password} # Exposed!interface Variable {
id: string;
name: string;
type: VariableType;
scope: VariableScope;
value: unknown;
defaultValue?: unknown;
description?: string;
isSecret: boolean;
}
interface VariableDefinition {
name: string;
type: VariableType;
scope: 'parameter' | 'return';
defaultValue?: unknown;
description?: string;
}
type VariableScope =
| 'global' // Suite level
| 'local' // Current diagram
| 'parameter' // Sub-diagram input
| 'return'; // Sub-diagram output# Generated from RPAForge global variables
# variables.py
# URLs
URL = "https://example.com"
API_URL = "https://api.example.com"
# Browser Settings
BROWSER = "chrome"
HEADLESS = False
TIMEOUT = 30
# Test Data
CREDENTIALS = ["user1", "user2", "user3"]
CONFIG = {
"api_endpoint": "/api/v1",
"retry_count": 3,
"screenshot_dir": "screenshots"
}from robot.libraries.BuiltIn import BuiltIn
def get_variable_value(name: str, default=None):
"""Get variable value from Robot Framework context."""
builtin = BuiltIn()
return builtin.get_variable_value(name, default)
def set_variable(name: str, value):
"""Set variable in Robot Framework context."""
builtin = BuiltIn()
builtin.set_suite_variable(f"${{{name}}}", value)