Skip to content

Commit f8060e5

Browse files
committed
doc: update get started/configuration
1 parent 691a0cc commit f8060e5

File tree

1 file changed

+172
-78
lines changed

1 file changed

+172
-78
lines changed

docs/02_get_started/configuration.md

Lines changed: 172 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2,142 +2,236 @@
22

33
## Introduction to the `robot.toml` File
44

5-
The `robot.toml` file provides a structured and flexible way to configure your Robot Framework project. Rather than relying on various argument files, batch files or command-line arguments, you can consolidate all key settings in this one centralized file. This makes it easier to manage and maintain settings across different environments and use cases.
5+
The `robot.toml` file serves as a centralized configuration system for your Robot Framework projects. Instead of managing multiple argument files, batch scripts, or command-line parameters, you can define all your project settings in one structured file.
66

7-
Similar to how `pyproject.toml` has become a standard for configuring Python projects, the `robot.toml` file aims to serve the same role for Robot Framework projects. It allows you to define project settings such as output directories, environment variables, and profiles for different testing scenarios. This unified configuration approach simplifies project management and makes it easier to share and version control configurations.
7+
Similar to how `pyproject.toml` has become the standard for Python project configuration, `robot.toml` aims to provide the same benefits for Robot Framework projects by:
88

9-
While the `robot.toml` file can be integrated with development environments like VS Code, its primary function is to centralize configuration for Robot Framework projects, streamlining the setup and maintenance process.
9+
- Centralizing all configuration in one location
10+
- Making settings easily shareable through version control
11+
- Supporting different environments through profiles
12+
- Providing a clear, readable format for configuration
1013

11-
This guide provides an overview of how to set up and use the `robot.toml` file to manage various aspects of your Robot Framework project.
12-
13-
---
14+
While fully compatible with development environments like VS Code, the `robot.toml` file is primarily designed to simplify Robot Framework project setup and maintenance.
1415

1516
## About TOML Files
1617

17-
TOML (Tom's Obvious, Minimal Language) is a file format designed to be easy to read and write due to its clear structure. TOML files use key-value pairs to define configuration settings, similar to JSON or YAML, but with a more human-friendly syntax. In the context of the `robot.toml` file, TOML is used to structure the configuration settings for your Robot Framework project, allowing for well-organized and readable project settings.
18+
TOML (Tom's Obvious, Minimal Language) is a configuration file format designed to be easy to read and write. It uses simple key-value pairs organized into sections, making it more human-friendly than formats like JSON or XML.
19+
20+
Example of TOML syntax:
21+
```toml
22+
# This is a comment
23+
key = "value"
24+
25+
[section]
26+
nested_key = "nested value"
27+
```
1828

19-
For a full and detailed description of the TOML format, please refer to the official [TOML documentation](https://toml.io/en/).
29+
For full details on TOML syntax, visit the [official TOML documentation](https://toml.io/en/).
2030

21-
---
31+
## Basic Configuration
2232

23-
## Configuring Settings
33+
### Core Settings
2434

25-
The `robot.toml` file allows you to configure various settings for your project. Below is an example that demonstrates how to configure the output directory, language preferences, and some global project variables. In TOML, `[variables]` is used to store multiple name-value pairs.
35+
Every command-line option available in Robot Framework can be configured in your `robot.toml` file:
2636

2737
```toml
38+
# Basic settings
2839
output-dir = "output"
40+
log-level = "INFO"
2941
languages = ["en", "fi"]
3042

43+
# Global variables
3144
[variables]
32-
NAME = "Tim"
33-
AGE = "25"
34-
MAIL = "hotmail.de"
45+
BROWSER = "Chrome"
46+
LOGIN_URL = "https://example.com/login"
47+
TIMEOUT = "20s"
3548
```
3649

37-
The key concept is that for every option you can set via the command line in a `robot` call, there is a corresponding key in the `robot.toml` file. Options that can be specified multiple times, such as `--variable` or `--tag`, are stored as lists. To view all available options, you can run `robot --help` in the command line or refer
50+
Multi-word options use hyphens in `robot.toml` (e.g., `--outputdir` becomes `output-dir`).
3851

39-
For better readability, multi-word options are written with hyphens in the `robot.toml` file. For example, `--outputdir` becomes `output-dir`. In addition to standard command-line options, the `robot.toml` file offers additional configuration settings. To view the full list, you can run the `robotcode config info` command or consult the [Configuration Reference](../03_reference/config.md).
52+
To see all available options:
53+
- Run `robot --help` for standard Robot Framework options
54+
- Run `robotcode config info` for RobotCode-specific options
55+
- Check the [Configuration Reference](../03_reference/config.md) documentation
4056

57+
## Working with Profiles
4158

42-
## Profiles
59+
Profiles allow you to define multiple configurations for different environments or testing scenarios.
4360

44-
Profiles in the `robot.toml` file allow you to store multiple configurations in an easily accessible way. This is particularly helpful when you need different settings for various testing environments, such as different platforms or testing conditions.
45-
46-
### Example of Profiles
47-
48-
Below is an example showing how to set up two profiles: `dev` and `prod`, each with distinct settings.
61+
### Creating Basic Profiles
4962

5063
```toml
64+
# Default settings (applies to all profiles)
65+
output-dir = "results"
66+
log-level = "INFO"
67+
68+
# Development environment profile
5169
[profiles.dev]
52-
output-dir = "output/dev"
53-
variables = { NAME = "Developer" }
70+
output-dir = "results/dev"
71+
variables = { ENVIRONMENT = "development", API_URL = "http://dev-api.example.com" }
5472

73+
# Production testing profile
5574
[profiles.prod]
56-
output-dir = "output/prod"
57-
variables = { NAME = "Production" }
75+
output-dir = "results/prod"
76+
variables = { ENVIRONMENT = "production", API_URL = "https://api.example.com" }
5877
```
5978

60-
### Inheriting Profiles
79+
### Profile Inheritance
6180

62-
Profiles can also inherit settings from each other to reduce duplication. The `inherits` keyword allows you to combine settings from multiple profiles.
81+
Profiles can inherit settings from other profiles to avoid duplication:
6382

6483
```toml
65-
[profiles.shared]
66-
output-dir = "output/shared"
84+
# Base profile with common settings
85+
[profiles.base]
86+
log-level = "INFO"
87+
variables = { TIMEOUT = "20s" }
6788

89+
# Development profile builds on base settings
6890
[profiles.dev]
69-
inherits = ["shared"]
70-
variables = { NAME = "Dev" }
91+
inherits = ["base"]
92+
variables = { ENVIRONMENT = "development", API_URL = "http://dev-api.example.com" }
93+
94+
# Testing profile also builds on base settings
95+
[profiles.test]
96+
inherits = ["base"]
97+
variables = { ENVIRONMENT = "testing", API_URL = "http://test-api.example.com" }
7198
```
7299

73-
### Hiding Profiles
100+
### Conditional Profiles
74101

75-
Profiles can be hidden using the `hidden` option or based on specific conditions through Python expressions.
102+
Profiles can be hidden or enabled based on conditions:
76103

77104
```toml
78-
[profiles.dev]
105+
# Hidden profile (not shown in listings)
106+
[profiles.internal]
79107
hidden = true
80108

81-
[profiles.dev]
82-
hidden.if = "platform.system()=='Windows'"
109+
# Conditionally enabled profiles
110+
[profiles.windows]
111+
enabled.if = "platform.system() == 'Windows'"
112+
variables = { DRIVER_PATH = "C:\\drivers" }
113+
114+
[profiles.linux]
115+
enabled.if = "platform.system() == 'Linux'"
116+
variables = { DRIVER_PATH = "/usr/local/bin" }
83117
```
84118

85-
### Enabling Profiles
119+
### Profile Precedence
86120

87-
Similarly, profiles can be enabled or disabled using the `enabled` option. This can also be based on user-defined conditions.
121+
When multiple profiles are used together, you can control which settings take priority:
88122

89123
```toml
90-
[profiles.dev]
91-
enabled = false
124+
# Base settings (low precedence)
125+
[profiles.base]
126+
variables = { LOG_LEVEL = "INFO", BROWSER = "chrome" }
127+
128+
# Override with higher precedence
129+
[profiles.debug]
130+
precedence = 100
131+
variables = { LOG_LEVEL = "DEBUG" }
132+
133+
# Highest priority settings
134+
[profiles.critical]
135+
precedence = 200
136+
variables = { RETRIES = 3 }
137+
```
92138

93-
[profiles.dev]
94-
enabled.if = "platform.system()=='Windows'"
139+
## Test Execution
140+
141+
### Running Tests with RobotCode
142+
143+
To execute tests, install the `robotcode-runner` package:
144+
145+
```bash
146+
pip install robotcode[runner]
95147
```
96148

97-
Disabled profiles cannot be merged or inherited from.
149+
Common test execution commands:
98150

99-
---
151+
```bash
152+
# Run all tests in a directory
153+
robotcode robot tests/
100154

101-
## Test Execution
155+
# Run with a specific profile
156+
robotcode -p dev robot tests/
157+
158+
# Combine multiple profiles
159+
robotcode -p base -p windows robot tests/
160+
161+
# Override variables on command line
162+
robotcode -p dev -v BROWSER:firefox robot tests/
163+
164+
# Run tests by tag
165+
robotcode robot -i smoke -i regression tests/
166+
```
167+
168+
You can also define paths directly in the configuration:
169+
170+
```toml
171+
paths = ["tests"]
172+
173+
```
102174

103-
To execute tests using the CLI, ensure that the `robotcode-runner` pip package is installed and added to your `requirements.txt` file.
175+
then it is not needed to give specific paths at the commandline, just type:
176+
177+
```bash
178+
# run all tests
179+
robotcode run
180+
181+
# run tests and only include/exclude tests with specific tags
182+
robotcode run -i regression -e wip
183+
```
184+
185+
## Advanced Configuration
186+
187+
### Extending vs. Replacing Settings
188+
189+
By default, when merging profiles, list and dictionary settings are completely replaced. To add to these settings instead, use the `extend-` prefix:
190+
191+
```toml
192+
# Default settings
193+
variables = { BROWSER = "chrome", TIMEOUT = "20s" }
194+
include = ["smoke"]
195+
196+
[profiles.api]
197+
# Completely replaces the default variables
198+
variables = { API_KEY = "123456" } # BROWSER and TIMEOUT are removed
199+
200+
[profiles.extended]
201+
# Adds to the default variables
202+
extend-variables = { API_KEY = "123456" } # Results in {BROWSER = "chrome", TIMEOUT = "20s", API_KEY = "123456"}
203+
extend-include = ["api"] # Results in ["smoke", "api"]
204+
```
104205

105-
### Executing Tests
206+
Settings that support the `extend-` prefix include:
207+
- `variables`
208+
- `include` / `exclude`
209+
- `python-path`
210+
- `metadata`
106211

107-
Here are some common ways to execute tests using the CLI:
212+
and many more, see the [`robot.toml` reference](../03_reference/config.md) for all posibilities.
108213

109-
- Execute all tests within a location:
110-
```bash
111-
robotcode robot PATH
112-
```
113-
Alternatively, you can specify paths in the `robot.toml` file:
114-
```toml
115-
paths = "TESTFILE_LOC"
116-
```
214+
## Configuration Loading Order
117215

118-
- Execute a specific test case:
119-
```bash
120-
robotcode robot -t "TEST_CASE_NAME"
121-
```
216+
RobotCode loads configuration files in a specific sequence, with each file potentially overriding settings from previous ones:
122217

123-
- Execute tests with a specific profile:
124-
```bash
125-
robotcode -p PROFILE_NAME robot PATH
126-
```
218+
1. **Global user configuration**
219+
- Located at `~/.robot.toml` (user's home directory)
220+
- Sets system-wide defaults
127221

128-
- Merge and execute tests from multiple profiles:
129-
```bash
130-
robotcode -p PROFILE_NAME_1 -p PROFILE_NAME_2 robot PATH
131-
```
222+
2. **Project `pyproject.toml`**
223+
- Located in the project root
224+
- Robot settings stored in the `[tool.robot]` section
132225

133-
- Execute tests with a variable override:
134-
```bash
135-
robotcode -p PROFILE_NAME -v NAME:Carl robot PATH
136-
```
226+
3. **Project `robot.toml`**
227+
- Located in the project root
228+
- Main project configuration (should be in version control)
137229

138-
- Execute tests by tag:
139-
```bash
140-
robotcode robot -i TAG_NAME
141-
```
230+
4. **Personal `.robot.toml`**
231+
- Located in the project root
232+
- User-specific overrides (should be added to `.gitignore`)
142233

143-
Tags can be set globally or individually for each test case.
234+
When multiple profiles are specified, they're applied in this order:
235+
1. Default settings (top-level settings not in any profile)
236+
2. Profiles ordered by precedence (lowest to highest)
237+
3. For equal precedence, the order specified on the command line

0 commit comments

Comments
 (0)