@@ -106,17 +106,21 @@ and their arguments, are separated from each others with two or more spaces.
106
106
An alternative is using the `pipe separated format `_ where the separator is
107
107
the pipe character surrounded with spaces (:codesc: `\ |\ `).
108
108
109
- Executed files typically use the :file: `.robot ` extension, but that ` can be
110
- configured `__ with the :option: ` --extension ` option . `Resource files `_
111
- can use the :file: ` .robot ` extension as well, but using the dedicated
112
- :file: ` .resource ` extension is recommended . Files containing non-ASCII
109
+ Suite files typically use the :file: `.robot ` extension, but what files are
110
+ parsed ` can be configured `__ . `Resource files `_ can use the :file: ` .robot `
111
+ extension as well, but using the dedicated :file: ` .resource ` extension is
112
+ recommended and may be mandated in the future . Files containing non-ASCII
113
113
characters must be saved using the UTF-8 encoding.
114
114
115
- Robot Framework also supports reStructuredText _ files so that normal
116
- Robot Framework data is `embedded into code blocks `__. It is possible to
117
- use either :file: `.rst ` or :file: `.rest ` extension with reStructuredText
118
- files, but the aforementioned :option: `--extension ` option `must be used `__
119
- to enable parsing them when executing a directory.
115
+ Robot Framework supports also reStructuredText _ files so that normal
116
+ Robot Framework data is `embedded into code blocks `__. Only files with
117
+ the :file: `.robot.rst ` extension are parsed by default. If you would
118
+ rather use just :file: `.rst ` or :file: `.rest ` extension, that needs to be
119
+ configured separately.
120
+
121
+ Robot Framework data can also be created in `JSON format `_ that is targeted
122
+ more for tool developers than normal Robot Framework users. Only JSON files
123
+ with the custom :file: `.rbt ` extension are parsed by default.
120
124
121
125
Earlier Robot Framework versions supported data also in HTML and TSV formats.
122
126
The TSV format still works if the data is compatible with the `space separated
@@ -129,9 +133,9 @@ format at all.
129
133
130
134
__ `Selecting files to parse `_
131
135
__ `reStructuredText format `_
132
- __ `Selecting files to parse `_
133
136
134
137
.. _space separated plain text format :
138
+ .. _plain text format :
135
139
136
140
Space separated format
137
141
~~~~~~~~~~~~~~~~~~~~~~
@@ -314,7 +318,116 @@ when processing files using reStructuredText tooling normally.
314
318
JSON format
315
319
~~~~~~~~~~~
316
320
317
- FIXME
321
+ Robot Framework supports data also in JSON _ format. This format is designed
322
+ more for tool developers than for regular Robot Framework users and it is not
323
+ meant to be edited manually. Its most important use cases are:
324
+
325
+ - Transferring data between processes and machines. A suite can be converted
326
+ to JSON in one machine and recreated somewhere else.
327
+ - Saving a suite constructed from normal Robot Framework data into a single
328
+ JSON file that is faster to parse.
329
+ - Alternative data format for external tools generating tests or tasks.
330
+
331
+ .. note :: The JSON data support is new in Robot Framework 6.1 and it can be
332
+ enhanced in future Robot Framework versions. If you have an enhancement
333
+ idea or believe you have encountered a bug, please submit an issue __
334
+ or start a discussion thread on the `#devel ` channel on our Slack _.
335
+
336
+ __ https://issues.robotframework.org
337
+
338
+ Converting suite to JSON
339
+ ''''''''''''''''''''''''
340
+
341
+ A suite structure can be serialized into JSON by using the `TestSuite.to_json `__
342
+ method. When used without arguments, it returns JSON data as a string, but
343
+ it also accepts a path or an open file where to write JSON data along with
344
+ configuration options related to JSON formatting:
345
+
346
+ .. sourcecode :: python
347
+
348
+ from robot.running import TestSuite
349
+
350
+
351
+ # Create suite based on data on the file system.
352
+ suite = TestSuite.from_file_system('/path/to/data')
353
+ # Get JSON data as a string.
354
+ data = suite.to_json()
355
+ # Save JSON data to a file with custom indentation.
356
+ suite.to_json('data.rbt', indent=2)
357
+
358
+ If you would rather work with Python data and then convert that to JSON
359
+ or some other format yourself, you can use `TestSuite.to_dict `__ instead.
360
+
361
+ __ https://robot-framework.readthedocs.io/en/master/autodoc/robot.running.html#robot.running.model.TestSuite.to_json
362
+ __ https://robot-framework.readthedocs.io/en/master/autodoc/robot.running.html#robot.running.model.TestSuite.to_dict
363
+
364
+ Creating suite from JSON
365
+ ''''''''''''''''''''''''
366
+
367
+ A suite can be constructed from JSON data using the `TestSuite.from_json `__
368
+ method. It works both with JSON strings and paths to JSON files:
369
+
370
+ .. sourcecode :: python
371
+
372
+ from robot.running import TestSuite
373
+
374
+
375
+ # Create suite from JSON data in a file.
376
+ suite = TestSuite.from_json('data.rbt')
377
+ # Create suite from a JSON string.
378
+ suite = TestSuite.from_json('{"name": "Suite", "tests": [{"name": "Test"}]}')
379
+
380
+ If you have data as a Python dictionary, you can use `TestSuite.from_dict `__
381
+ instead.
382
+
383
+ __ https://robot-framework.readthedocs.io/en/master/autodoc/robot.running.html#robot.running.model.TestSuite.from_json
384
+ __ https://robot-framework.readthedocs.io/en/master/autodoc/robot.running.html#robot.running.model.TestSuite.from_dict
385
+
386
+ Executing JSON files
387
+ ''''''''''''''''''''
388
+
389
+ When using the `robot ` command normally, JSON files with the :file: `.rbt `
390
+ extension are parsed automatically. This includes running individual JSON files
391
+ like `robot tests.rbt ` and running directories containing :file: `.rbt ` files.
392
+ If you would rather use the standard :file: `.json ` extension, you need to
393
+ `configure which files are parsed `__.
394
+
395
+ __ `Selecting files to parse `_
396
+
397
+ Adjusting suite source
398
+ ''''''''''''''''''''''
399
+
400
+ Suite source in the data got from `TestSuite.to_json ` and `TestSuite.to_dict `
401
+ is in absolute format. If a suite is recreated later on a different machine,
402
+ the source may thus not match the directory structure on that machine. To
403
+ avoid that, it is possible to use the `TestSuite.adjust_source `__ method to
404
+ make the suite source relative before getting the data and add a correct root
405
+ directory after the suite is recreated:
406
+
407
+ .. sourcecode :: python
408
+
409
+ from robot.running import TestSuite
410
+
411
+
412
+ # Create a suite, adjust source and convert to JSON.
413
+ suite = TestSuite.from_file_system('/path/to/data')
414
+ suite.adjust_source(relative_to='/path/to')
415
+ suite.to_json('data.rbt')
416
+
417
+ # Recreate suite elsewhere and adjust source accordingly.
418
+ suite = TestSuite.from_json('data.rbt')
419
+ suite.adjust_source(root='/new/path/to')
420
+
421
+ __ https://robot-framework.readthedocs.io/en/master/autodoc/robot.running.html#robot.running.model.TestSuite.adjust_source
422
+
423
+ JSON structure
424
+ ''''''''''''''
425
+
426
+ Imports, variables and keywords created in suite files are included in the
427
+ generated JSON along with tests and tasks. The exact JSON structure is documented
428
+ in the :file: `running.json ` `schema file `__.
429
+
430
+ __ https://github.com/robotframework/robotframework/tree/master/doc/schema#readme
318
431
319
432
Rules for parsing the data
320
433
--------------------------
0 commit comments