You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In many Robot Framework projects, there is a temptation to simplify setup by consolidating all resources and libraries into one global file—often named something like `Keywords.resource`—which is then usually the only resource imported into suites and other resource files. At first glance, this strategy appears to streamline the project structure by reducing the number of explicit imports and centralizing common functionality. However, while this approach may save time during initial configuration, it masks underlying design issues and introduces several long-term challenges. These challenges range from complex circular dependencies and naming collisions to performance slowdowns and decreased maintainability, which ultimately hinder the scalability and robustness of the test suite.
3
+
## Introduction
4
+
5
+
In many Robot Framework projects, there is a temptation to simplify setup by consolidating all resources and libraries into one global file—often named something like `Keywords.resource`—which is then usually the only resource imported into suites and other resource files.
6
+
7
+
**Executive Summary**: While global resource files might seem convenient initially, they lead to circular dependencies, keyword ambiguities, performance issues, and maintenance challenges. This guide explains the problems of this approach and offers a modular alternative that improves code organization, maintainability, and performance.
4
8
5
9
## Why This Approach is Problematic
6
10
@@ -19,9 +23,38 @@ In many Robot Framework projects, there is a temptation to simplify setup by con
19
23
-**Creation of Unnecessary References:**
20
24
Relying on a centralized file forces all suites and resource files to reference the same global file, even if they only need a subset of its contents. This means that every suite is indirectly coupled to every keyword and variable in that file, regardless of whether they are used. Such an arrangement makes it difficult to determine which keywords are actually needed for a given suite. When updates or refactoring are required, developers may unintentionally modify or remove elements that other parts of the project still depend on. This extra layer of indirection complicates resource tracking, increases the likelihood of errors during maintenance, and can create confusion in larger teams where multiple developers modify the global file simultaneously.
21
25
26
+
### Example of Problematic Global Resource File
27
+
28
+
Consider this example of a typical global resource file that causes issues:
29
+
30
+
```robot
31
+
*** Settings ***
32
+
# Global.resource - tries to do everything
33
+
Library SeleniumLibrary
34
+
Library RequestsLibrary
35
+
Library DatabaseLibrary
36
+
Library OperatingSystem
37
+
Resource LoginKeywords.resource
38
+
Resource CustomerKeywords.resource
39
+
Resource OrderKeywords.resource
40
+
Resource ApiKeywords.resource
41
+
Resource ReportingKeywords.resource
42
+
# ...and 20+ more imports
43
+
44
+
*** Variables ***
45
+
${GLOBAL_URL} https://example.com
46
+
${DB_CONNECTION} connection_string
47
+
# ...hundreds of variables for different modules
48
+
49
+
*** Keywords ***
50
+
# 500+ keywords covering every aspect of the system
51
+
```
52
+
53
+
When this file gets imported into multiple other resources and suite files, it creates a tangled web of dependencies.
54
+
22
55
## Documenting with Suite Settings
23
56
24
-
Declaring libraries and resources in the suite settings is not only a configuration step—it also serves as essential documentation. Test suites and test cases are more than just executable code; they document which functional areas of the application are under test. By explicitly declaring the required libraries and resources (e.g., for login processes, customer management, or database validations), you provide clear insight into the suite’s focus.
57
+
Suite settings do more than just configure your test environment—they serve as essential documentation for your project. When you explicitly declare libraries, resources and also variables in your settings section, you're creating a clear record of which technical or functional areas of the application are being used in this file. This transparency helps team members, stakeholders, and testers quickly understand the suite's purpose.
This explicit declaration improves maintainability and helps new team members, stakeholders, and automated systems quickly understand the application areas being validated.
68
+
This declaration immediately communicates that this suite deals with login processes, customer management, and database validation—improving maintainability and knowledge transfer within your team.
36
69
37
70
## Limitations in Import and Package Management
38
71
@@ -95,9 +128,8 @@ project/
95
128
└── tests/
96
129
├── api/
97
130
│ └── customer_api_tests.robot # Imports only api/customers.resource
98
-
├── api/
99
-
└── business/
100
-
└── contracts.robot # Imports only ui/login_page.resource
131
+
├── business/
132
+
│ └── contracts.robot # Imports only ui/login_page.resource
101
133
└── ui_tests/
102
134
└── login_tests.robot # Imports only ui/login_page.resource
103
135
```
@@ -149,32 +181,97 @@ If you have an existing project with a large global resource file, consider this
149
181
- Remove those keywords from the global file
150
182
- Eventually phase out the global file completely
151
183
152
-
For keywords that are genuinely used everywhere, consider keeping a minimal `common.resource` file, but ensure it only contains truly global utilities.
184
+
Here's a concrete example of refactoring from a global approach to a modular one:
185
+
186
+
**Before (Global.resource):**
187
+
```robot
188
+
*** Settings ***
189
+
Library SeleniumLibrary
190
+
Library RequestsLibrary
191
+
192
+
*** Keywords ***
193
+
Login To Application
194
+
[Arguments] ${username} ${password}
195
+
Open Browser ${URL} ${BROWSER}
196
+
Input Text id=username ${username}
197
+
Input Password id=password ${password}
198
+
Click Button id=login-button
199
+
200
+
Get Customer Details
201
+
[Arguments] ${customer_id}
202
+
${response}= GET ${API_URL}/customers/${customer_id}
203
+
[Return] ${response.json()}
204
+
```
205
+
206
+
**After:**
207
+
208
+
**/resources/ui/login.resource:**
209
+
```robot
210
+
*** Settings ***
211
+
Library SeleniumLibrary
212
+
213
+
*** Keywords ***
214
+
Login To Application
215
+
[Arguments] ${username} ${password}
216
+
Open Browser ${URL} ${BROWSER}
217
+
Input Text id=username ${username}
218
+
Input Password id=password ${password}
219
+
Click Button id=login-button
220
+
```
221
+
222
+
**/resources/api/customers.resource:**
223
+
```robot
224
+
*** Settings ***
225
+
Library RequestsLibrary
226
+
227
+
*** Keywords ***
228
+
Get Customer Details
229
+
[Arguments] ${customer_id}
230
+
${response}= GET ${API_URL}/customers/${customer_id}
231
+
[Return] ${response.json()}
232
+
```
233
+
234
+
**/tests/login_test.robot:**
235
+
```robot
236
+
*** Settings ***
237
+
Resource resources/ui/login.resource
238
+
# Only importing what is needed
239
+
240
+
*** Test Cases ***
241
+
Valid Login
242
+
Login To Application valid_user valid_password
243
+
```
244
+
245
+
## When Restructuring Isn't Possible
153
246
247
+
If restructuring your project isn't an option, you can mitigate potential issues by managing warnings from your development environment. For example, you can suppress warnings related to circular dependencies and redundant imports on a per-file basis or globally.
154
248
155
-
## When Restructuring Isn’t Possible
249
+
It's important to understand that suppressing warnings doesn't fix the underlying issues—it merely acknowledges them. When you choose to ignore specific diagnostics, you're making a conscious decision that these particular issues are acceptable in your codebase. This explicit acknowledgment is different from simply ignoring random warnings in your IDE. By documenting suppressions in your code or configuration files, you're communicating to your team that you understand the potential problem but have determined that it's an acceptable compromise given your project's constraints.
156
250
157
-
If restructuring your project isn’t an option, you can mitigate potential issues by managing warnings from your development environment. For example, you can suppress warnings related to circular dependencies and redundant imports on a per-file basis or globally.
251
+
This approach is particularly useful during transitional periods or when working with legacy codebases where perfect architectural solutions aren't immediately feasible. However, these suppressions should ideally be revisited periodically to determine if the underlying issues can eventually be resolved through refactoring.
158
252
159
253
### Suppress Warnings in Specific Files
160
254
161
255
Use directives to disable warnings for circular dependencies and already-imported resources on a per-file basis.
For global suppression in VS Code, add the following to your `settings.json`:
270
+
The preferred approach to suppress warnings globally is using a `robot.toml` configuration file. This method is IDE-independent and can be checked into version control to share with your team. Create a [`robot.toml`](/03_reference/config) file in your project root with these contents:
@@ -183,11 +280,10 @@ For global suppression in VS Code, add the following to your `settings.json`:
183
280
]
184
281
```
185
282
186
-
Alternatively, to remain IDE-independent, use a [`robot.toml`](/03_reference/config) file with these contents:
283
+
Alternatively, if you're working exclusively in VS Code, you can add the following to your `settings.json`, though this approach is not recommended for team environments as it only affects your local setup:
0 commit comments