Tasks
In Robot Framework for RPA, Tasks are where the action happens. When run, the robot script will execute the keywords specified in its tasks in sequence.
Take this example .robot
file:
This script has one Task that we called Download an Excel file, open it, and close it
.
To accomplish the task, we call three keywords: Download
, Open Workbook
, and Close Workbook
.
Tasks basic syntax
Tasks must be contained in a *** Tasks ***
section.
The first line contains the name of the task. All other lines need to be indented with spaces.
Tasks documentation
Using the [Documentation]
setting, you can add a more detailed description of what the task does:
Task setup and teardown
Using the [Setup]
and [Teardown]
settings, you can execute keywords before and after a task is run:
The [Setup]
setting will always execute as the first action called by the Task section. Likewise the [Teardown]
setting will always execute as the last keyword, even upon a failure. The [Teardown]
setting is great to use to ensure that specific cleanup actions are taken by the bot in both successful as well as failed runs.
Additionally, you can also place both the [Setup]
and [Teardown]
settings in the settings section like the below example. The below example also demonstrates how the [Teardown]
setting works in conjunction with a failure.
The [Setup]
and [Teardown]
setting also work in conjuction with Work Data Management / Work Items.
For information on handling Work Item failures refer to the work items page. The portal bot Producer-Consumer template also demonstrates how to handle work item failures.
You can find information on handling task errors on our linked docs page.
TRY-EXCEPT blocks are also perfect for handling errors, in keywords, tasks, or for Work Items.