Configuring Projects with robot.toml
Every run of a Robot Framework project needs options: where the tests are, where Robot Framework finds the libraries and resource files, variables such as the browser or the address of the system under test, and where the results go. On the command line, they make long commands. Kept in argument files and shell scripts, they get copied for every environment, and every editor needs them set up again.
robot.toml keeps these options in one file in the project, and profiles hold what differs between environments:
paths = ["tests"]python-path = ["libraries", "resources"]
[variables]BASE_URL = "http://localhost:8080"
[profiles.staging.extend-variables]BASE_URL = "https://staging.shop.example"robotcode run runs the tests in tests against the local server, and robotcode -p staging run runs them against the staging server. VS Code and PyCharm use the same file, so a run in the editor gets the same options as a run on the command line or on a CI server. To create a first robot.toml, see Configure Your Project; the robot.toml reference lists every setting.
Who reads robot.toml
Section titled “Who reads robot.toml”- Every
robotcodecommand, fromrobotcode run,discoverandanalyze codetorepl,docandresults: each finds the project root and reads the configuration there, with the profiles you select. - RobotCode's language server in VS Code, PyCharm and other editors, for the analysis of your files, the test discovery and runs.
Robot Framework's own robot command does not read robot.toml. Run your tests with robotcode run, or robotcode robot, which is the same command and passes the configuration on to Robot Framework. On the command line, robotcode run needs RobotCode's runner in the environment of your project, for example installed with pip install "robotcode[runner]".
An example project
Section titled “An example project”The pages of this guide build on a project that tests a web shop. Its robot.toml is committed with the project:
paths = ["tests"]python-path = ["libraries", "resources"]output-dir = "results"
[variables]BROWSER = "chromium"HEADLESS = "false"BASE_URL = "http://localhost:8080"
[profiles.staging]description = "Staging shop"
[profiles.staging.extend-variables]BASE_URL = "https://staging.shop.example"
[profiles.ci]description = "CI server"inherits = ["staging"]output-dir = "results/ci"
[profiles.ci.extend-variables]HEADLESS = "true"- The settings at the top are the options of every run: the tests in
tests, libraries and resource files inlibrariesandresources, the results inresults, and three variables. - The profile
stagingruns the tests against the staging shop.extend-variableschangesBASE_URLand keeps the other variables. - The profile
ciis meant for the CI server. It inherits everything fromstaging, writes its results toresults/ciand runs the browser without a window.
One developer prefers Firefox and keeps that in a .robot.toml next to robot.toml, which is not committed:
[extend-variables]BROWSER = "firefox"With these files:
| Command | Runs the tests |
|---|---|
robotcode run |
Against http://localhost:8080 in Firefox, results in results |
robotcode -p staging run |
Against the staging shop in Firefox |
robotcode -p ci run on the CI server, without .robot.toml |
Against the staging shop in Chromium without a window, results in results/ci |
In the editors
Section titled “In the editors”- The analysis takes
python-path,variables,variable-files,envandlanguagesfrom the configuration, so that imports and variables resolve as they do in a run. - The test discovery and runs use all settings, as
robotcode rundoes. - Profiles: VS Code and PyCharm use the profiles you select there, and without a selection the default profiles. In VS Code, RobotCode: Select Configuration Profiles selects them, and the Test Explorer offers a run profile for each profile, named after the profile and its description, such as "Run ci - CI server"; see Configuration profiles. In PyCharm, Tools | RobotCode | Select Configuration Profiles... selects them, and Run with Profile... runs once with another one; see Configuration profiles.
- Changes apply at once: the editors restart RobotCode's language server when you create, change or delete
robot.toml,.robot.tomlorpyproject.toml. - Writing the file: in VS Code, the extension Even Better TOML completes the settings of
robot.tomland.robot.tomland shows their documentation; see Editingrobot.toml. PyCharm completes the settings of both files without further setup. Other editors with a TOML language server can use RobotCode's JSON schema athttps://www.robotcode.io/schemas/robot.toml.json.
Pages of this guide
Section titled “Pages of this guide”Released under the Apache-2.0. Copyright © 2022-present Daniel Biehl