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:

*** Settings ***
Documentation     Example robot that downloads a remote Excel file and opens it.
Library           RPA.Excel.Files
Library           RPA.HTTP

*** Tasks ***
Download an Excel file, open it, and close it
    Download    https://robotsparebinindustries.com/SalesData.xlsx    overwrite=True
    Open Workbook    Data.xlsx
    Close Workbook

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 singular form *** Task *** also works, but we suggest to use *** Tasks *** for better compatibility with Robocorp Lab notebook mode.

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:

*** Settings ***
Documentation     Example robot that downloads a remote Excel file and opens it.
Library           RPA.Excel.Files
Library           RPA.HTTP

*** Tasks ***
Download an Excel file, open it, and close it
    [Documentation]    Downloads the sales data file from the intranet, opens it, and closes it.
    Download    https://robotsparebinindustries.com/SalesData.xlsx    overwrite=True
    Open Workbook    Data.xlsx
    Close Workbook

Task setup and teardown

Using the [Setup] and [Teardown] settings, you can execute keywords before and after a task is run:

*** Settings ***
Documentation     Example robot that takes a screenshot of a webpage.
Library           RPA.Browser

*** Tasks ***
Take a screenshot of the intranet homepage
    [Setup]    Open Available Browser    https://robotsparebinindustries.com/
    Screenshot
    [Teardown]    Close All Browsers