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 an 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 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 an Excel file and opens it.

Library             RPA.Excel.Files
Library             RPA.HTTP


*** Tasks ***
Download an Excel file, open it, and close it
    [Documentation]    Download the sales data file, open it, and close 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.Selenium


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