|
1 | 1 | # Configuration
|
2 | 2 |
|
3 |
| -## Introducing the `robot.toml` file |
| 3 | +## Introduction to the `robot.toml` File |
4 | 4 |
|
5 |
| -The `robot.toml` file offers an alternative way of setting up your project in VS Code. Usually, those settings would be done via the `settings.json` file, doing so comes though at the cost of several limitations and inconveniences. Using `robot. toml` alleviates many of those by: |
| 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. |
6 | 6 |
|
7 |
| -- providing a simpler way of defining settings for the Robot Framework project in one file |
8 |
| -- creating a file that can be easily shared and uploaded to a git repository |
9 |
| -- removing the need to create an argument file |
10 |
| -- simplifying the command line execution |
11 |
| -- allowing to define multiple, easily expandable, profiles |
| 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. |
12 | 8 |
|
13 |
| -::: info |
14 |
| -The following documentation serves as a quick introduction on how to use the `robot.toml` file and will not cover all *Robot Framework* command line options. For a complete documentation of these options, please refer to the [Robot Framework User Guide](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html "Robot Framework User Guide"). |
15 |
| -::: |
| 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. |
16 | 10 |
|
17 |
| -::: tip |
18 |
| -If you want to have code completion and such things for TOML files, install the **[Even Better TOML](https://marketplace.visualstudio.com/items?itemName=tamasfe.even-better-toml)** extension before attempting to work with `robot.toml`. |
19 |
| -::: |
| 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. |
20 | 12 |
|
| 13 | +--- |
21 | 14 |
|
22 |
| -## Settings configuration |
| 15 | +## About TOML Files |
23 | 16 |
|
24 |
| -Using the `robot.toml` file, we can configure a wide range of settings for our project. The example below shows how we can setup the output directory, language and global project variables. In toml, `[variables]` is a tabular setting, meaning it can store multiple name-value pairs. |
| 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. |
25 | 18 |
|
26 |
| -```toml |
27 |
| -output-dir = "output" |
28 |
| -languages = ["english"] |
29 |
| - |
30 |
| -[variables] |
31 |
| -NAME = "Tim" |
32 |
| -AGE = "25" |
33 |
| -MAIL = "hotmail.de" |
34 |
| -``` |
35 |
| - |
36 |
| -You can access a full list of available setting by excetuting `robot --help` in the CLI. |
37 |
| - |
38 |
| - |
39 |
| -## Profiles |
40 |
| - |
41 |
| -Profiles allow you to store multiple configurations, in an easily accessible way. This can be useful if for example you need a different set of configurations, for testing on multiple platforms. Profiles are easily expandable and can be easily shared between developers by simply providing them the robot.toml file. |
42 |
| - |
43 |
| - |
44 |
| -### Defining profiles |
45 |
| - |
46 |
| -You can define a profile with `[profiles.YOUR_PROFILE_NAME]`. Follow it up with the settings that you want to configure for that particular profile. For tabular settings like `[variables]` you will need to create a separate entry using `[profiles.YOUR_PROFILE_NAME.variables]`. Your profiles will use any global configuration, that has not been defined within the profile. In example below, dev2 will use English as the language and *output* as the output directory. |
47 |
| - |
48 |
| -```toml |
49 |
| -output-dir = "output" |
50 |
| -languages = ["english"] |
51 |
| - |
52 |
| -[variables] |
53 |
| -NAME = "Tim" |
54 |
| -AGE = "25" |
55 |
| -MAIL = "hotmail.de" |
56 |
| - |
57 |
| -[profiles.dev1] |
58 |
| -output-dir = "dev1output" |
59 |
| -languages = ["german"] |
60 |
| - |
61 |
| -[profiles.dev1.variables] |
62 |
| -NAME = "Lisa" |
63 |
| -AGE = "32" |
64 |
| -MAIL = "web.de" |
65 |
| - |
66 |
| -[profiles.dev2.variables] |
67 |
| -NAME = "Andrew" |
68 |
| -AGE = "19" |
69 |
| -MAIL = "gmail.com" |
70 |
| - |
71 |
| -[profiles.dev3] |
72 |
| -output-dir = "dev3output" |
73 |
| -``` |
| 19 | +For a full and detailed description of the TOML format, please refer to the official [TOML documentation](https://toml.io/en/). |
74 | 20 |
|
| 21 | +--- |
75 | 22 |
|
76 |
| -### Overriding and extending settings |
| 23 | +## Configuring Settings |
77 | 24 |
|
78 |
| -Tabular settings like `[variables]` can be either overridden or expanded. In the example below, dev1 and dev2 are overriding `[variables]`. Override will prevent dev1 and dev2 from using any of the values defined in lines 4-7. This means that dev2 will not use `NAME = "Tim"` defined in line 5 but instead whatever is defined in the relevant .robot files. |
| 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. |
79 | 26 |
|
80 | 27 | ```toml
|
81 | 28 | output-dir = "output"
|
82 |
| -languages = ["english"] |
| 29 | +languages = ["en", "fi"] |
83 | 30 |
|
84 | 31 | [variables]
|
85 | 32 | NAME = "Tim"
|
86 | 33 | AGE = "25"
|
87 | 34 | MAIL = "hotmail.de"
|
88 |
| - |
89 |
| -[profiles.dev1.variables] |
90 |
| -NAME = "Lisa" |
91 |
| -AGE = "32" |
92 |
| -MAIL = "web.de" |
93 |
| - |
94 |
| -[profiles.dev2.variables] |
95 |
| -AGE = "19" |
96 |
| -MAIL = "gmail.com" |
97 | 35 | ```
|
98 | 36 |
|
99 |
| -In order to change only selected values or add new ones, the 'extend-' prefix is needed. In the example below, dev2 will still use `NAME` and `AGE` defined in lines 2 and 3. |
| 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 |
100 | 38 |
|
101 |
| -```toml |
102 |
| -[variables] |
103 |
| -NAME = "Tim" |
104 |
| -AGE = "25" |
105 |
| -MAIL = "hotmail.de" |
106 |
| - |
107 |
| -[profiles.dev2.extend-variables] |
108 |
| -MAIL = "gmail.com" |
109 |
| -LOCATION = "Berlin" |
110 |
| -``` |
| 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). |
111 | 40 |
|
112 | 41 |
|
113 |
| -### Inheriting and merging profiles |
| 42 | +## Profiles |
114 | 43 |
|
115 |
| -Profiles can inherit from an already existing profile. |
| 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. |
116 | 45 |
|
117 |
| -```toml |
118 |
| -[profiles.dev3] |
119 |
| -output-dir = "dev3output" |
| 46 | +### Example of Profiles |
120 | 47 |
|
121 |
| -[profiles.inheritedFromDev3] |
122 |
| -inherits = ["dev3"] |
123 |
| -languages = ["german"] |
124 |
| -``` |
125 |
| - |
126 |
| -It is also possible to inherit from multiple profiles. |
| 48 | +Below is an example showing how to set up two profiles: `dev` and `prod`, each with distinct settings. |
127 | 49 |
|
128 | 50 | ```toml
|
129 |
| -[profiles.dev1] |
130 |
| -output-dir = "dev1output" |
131 |
| -languages = ["german"] |
132 |
| - |
133 |
| -[profiles.dev1.variables] |
134 |
| -NAME = "Lisa" |
135 |
| -AGE = "32" |
136 |
| -MAIL = "web.de" |
| 51 | +[profiles.dev] |
| 52 | +output-dir = "output/dev" |
| 53 | +variables = { NAME = "Developer" } |
137 | 54 |
|
138 |
| -[profiles.dev3] |
139 |
| -output-dir = "dev3output" |
140 |
| - |
141 |
| -[profiles.dev1and3] |
142 |
| -inherits = ["dev1, dev3"] |
| 55 | +[profiles.prod] |
| 56 | +output-dir = "output/prod" |
| 57 | +variables = { NAME = "Production" } |
143 | 58 | ```
|
144 | 59 |
|
145 |
| -If a variable is present in multiple of the inherited profiles, the value of that variable will be the one, present in the last relevant inherited profile. In the example above, the value of `output-dir` for the dev1and2 profile, will be "dev3output". |
146 |
| - |
147 |
| - |
148 |
| -### Profile management |
149 |
| - |
150 |
| -#### Selecting profiles |
151 |
| - |
152 |
| -You can select a profile to work with, by entering "RobotCode: Select Configuration Profiles" in the command palette (ctrl+shift+p). |
| 60 | +### Inheriting Profiles |
153 | 61 |
|
154 |
| - |
155 |
| - |
156 |
| -Should you select more than one profile, a merged version of those profiles will be executed. |
157 |
| -Alternatively, you can select a profile to run or debug with, by clicking on the buttons, marked in the image below. |
158 |
| - |
159 |
| - |
160 |
| - |
161 |
| -Using this method however, does not allow you to select multiple profiles at once. |
162 |
| - |
163 |
| - |
164 |
| -#### Default profiles |
165 |
| - |
166 |
| -It is possible to select a list of default profiles, using the `default-profiles` option. Those profiles will be selected by default, if no other profile has been selected for execution. |
167 |
| -Should you select more than one default profile, a merged version of those profiles will be executed. |
| 62 | +Profiles can also inherit settings from each other to reduce duplication. The `merge` keyword allows you to combine settings from multiple profiles. |
168 | 63 |
|
169 | 64 | ```toml
|
170 |
| -default-profiles = ["dev1", "dev2"] |
171 |
| - |
172 |
| -[profiles.dev1.variables] |
173 |
| -NAME = "Lisa" |
174 |
| -AGE = "32" |
175 |
| -MAIL = "web.de" |
176 |
| - |
177 |
| -[profiles.dev2.variables] |
178 |
| -AGE = "19" |
179 |
| -MAIL = "gmail.com" |
180 |
| - |
181 |
| -[profiles.dev3.variables] |
182 |
| -MAIL = "hotmail.com" |
| 65 | +[profiles.shared] |
| 66 | +output-dir = "output/shared" |
183 | 67 |
|
| 68 | +[profiles.dev] |
| 69 | +merge = ["shared"] |
| 70 | +variables = { NAME = "Dev" } |
184 | 71 | ```
|
185 | 72 |
|
| 73 | +### Hiding Profiles |
186 | 74 |
|
187 |
| -#### Hiding profiles |
188 |
| - |
189 |
| -If, for whatever reason, you wish for individual profiles to not be displayed as selectable options, you can hide them by using the `hidden` option. |
| 75 | +Profiles can be hidden using the `hidden` option or based on specific conditions through Python expressions. |
190 | 76 |
|
191 | 77 | ```toml
|
192 |
| -[profiles.dev1] |
| 78 | +[profiles.dev] |
193 | 79 | hidden = true
|
194 |
| -``` |
195 |
| - |
196 |
| -It is also possible to hide a profile based on user defined conditions, using python expressions. |
197 | 80 |
|
198 |
| -```toml |
199 |
| -[profiles.dev1] |
| 81 | +[profiles.dev] |
200 | 82 | hidden.if = "platform.system()=='Windows'"
|
201 | 83 | ```
|
202 | 84 |
|
203 |
| -Hidden profiles can be still merged and inherited from. |
204 |
| - |
| 85 | +### Enabling Profiles |
205 | 86 |
|
206 |
| -#### Enabling profiles |
207 |
| - |
208 |
| -Similar to hiding, profiles can be also disabled using the `enabled` option. |
| 87 | +Similarly, profiles can be enabled or disabled using the `enabled` option. This can also be based on user-defined conditions. |
209 | 88 |
|
210 | 89 | ```toml
|
211 |
| -[profiles.dev1] |
| 90 | +[profiles.dev] |
212 | 91 | enabled = false
|
213 |
| -``` |
214 | 92 |
|
215 |
| -It is also possible to enable or disable a profile based on user defined conditions, using python expressions. |
216 |
| - |
217 |
| -```toml |
218 |
| -[profiles.dev1] |
| 93 | +[profiles.dev] |
219 | 94 | enabled.if = "platform.system()=='Windows'"
|
220 | 95 | ```
|
221 | 96 |
|
222 | 97 | Disabled profiles cannot be merged or inherited from.
|
223 | 98 |
|
| 99 | +--- |
224 | 100 |
|
225 |
| -### Test Execution |
226 |
| - |
227 |
| -In order to execute tests using the CLI, you will need to install the `robotcode-runner` pip package and add it to your requirements.txt. |
228 |
| - |
229 |
| - |
230 |
| -#### Executing tests |
231 |
| - |
232 |
| -Here are some of the most common ways, to execute tests via the CLI. |
233 |
| - |
234 |
| - |
235 |
| -- `robotcode robot PATH` |
236 |
| - |
237 |
| - Executes all tests (including in subfolders) within a given location. This command can be also executed with the command `robotcode robot`, if you add `paths = "TESTFILE_LOC"` to your robot.toml file. |
238 |
| - |
239 |
| -- `robotcode robot -t "TEST_CASE_NAME"` |
240 |
| - |
241 |
| - Executes the test case called `TEST_CASE_NAME` |
| 101 | +## Test Execution |
242 | 102 |
|
243 |
| -- `robotcode -p PROFILE_NAME robot PATH` |
| 103 | +To execute tests using the CLI, ensure that the `robotcode-runner` pip package is installed and added to your `requirements.txt` file. |
244 | 104 |
|
245 |
| - Executes all tests (including in subfolders) within a given location, with the selected profile. |
| 105 | +### Executing Tests |
246 | 106 |
|
247 |
| -- `robotcode -p PROFILE_NAME_1 -p PROFILE_NAME_2 robot PATH` |
| 107 | +Here are some common ways to execute tests using the CLI: |
248 | 108 |
|
249 |
| - Executes all tests (including in subfolders) within a given location, with a merged version the selected profiles. |
| 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 | + ``` |
250 | 117 |
|
251 |
| -- `robotcode -p PROFILE_NAME -v NAME:Carl robot PATH` |
| 118 | +- Execute a specific test case: |
| 119 | + ```bash |
| 120 | + robotcode robot -t "TEST_CASE_NAME" |
| 121 | + ``` |
252 | 122 |
|
253 |
| - Executes all tests (including in subfolders) within a given location. Changes the value of the variable `NAME` to `Carl`. |
| 123 | +- Execute tests with a specific profile: |
| 124 | + ```bash |
| 125 | + robotcode -p PROFILE_NAME robot PATH |
| 126 | + ``` |
254 | 127 |
|
| 128 | +- Merge and execute tests from multiple profiles: |
| 129 | + ```bash |
| 130 | + robotcode -p PROFILE_NAME_1 -p PROFILE_NAME_2 robot PATH |
| 131 | + ``` |
255 | 132 |
|
256 |
| -- `robotcode robot -i TAG_NAME` |
| 133 | +- Execute tests with a variable override: |
| 134 | + ```bash |
| 135 | + robotcode -p PROFILE_NAME -v NAME:Carl robot PATH |
| 136 | + ``` |
257 | 137 |
|
258 |
| - Executes all tests with a given tag. Tags can be assigned either globally in the settings or individually for each test case. |
| 138 | +- Execute tests by tag: |
| 139 | + ```bash |
| 140 | + robotcode robot -i TAG_NAME |
| 141 | + ``` |
259 | 142 |
|
260 |
| - <IMG src="images/tags_robot.PNG"/> |
| 143 | +Tags can be set globally or individually for each test case. |
0 commit comments