Note: You are looking at a static snapshot of documentation related to Robot Framework automations. The most recent documentation is at https://robocorp.com/docs

Your first robot

Introduction to robots 🤖

A brief pause to go through what we mean by a robot. In Robocorp terminology, a robot is a folder or a zip file packaged in a specific way that contains everything needed to run the automation.

All robot files share the same structure, they consist of:

  1. Suites — the robot files that are called when the robot runs,
  2. Resources — user keywords and variables that you can share between tasks and suites
  3. Locators — UI elements that can be interacted with in apps and web pages
  4. Assets and Configuration — images, code library dependencies, and robot entry points when called from Control Room
Structure of Robots

Suites allow you to structure your robots. Simple robots may have just one suite, but a more complex robot can be split into multiple suites that can be run separately from Control Room.

Each suite may have:

  1. Tasks — these are the actual commands that can be run for this robot
  2. User Keywords — reusable functionality that you use to organize your robots
  3. Variables — saved values, such as numbers, strings, or lists
  4. Settings — suite configuration

Don't worry too much about these yet, in this course we'll build just a simple robot, with one suite and one task!

If you wish to go deeper into how robots are organized, have a look at Robot structure & configuration and Basic concepts of Robot Framework.

View the structure of your robot

Once you have your newly created robot open in VS Code, you will see files on the left of the screen. The robot needs to have those files in place to work correctly. Read about the robot structure, if you are interested (not necessary to complete this course!).

Robot file structure

.gitignore conda.yaml LICENSE README.md robot.yaml tasks.robot

Open the robot file

Click the tasks.robot file to open it in the editor. The robot looks something like this:

*** Settings *** Documentation Template robot main suite. *** Tasks *** Minimal task Log Done.

The task of this robot is to write a log entry saying "Done.". As you can see, the syntax is human-readable!

Run the robot

Great! Let's try running this simple robot to see what happens.

There are two main ways to run your robot. You can clickety-click with your mouse or typety-type with your keyboard. Let's look at both options.

Run the robot from the Robocorp Code extension user interface

Look at the left side of your VS Code screen. There's a vertical bar with a bunch of icons. You should see a monkey icon there. That's the icon for the Robocorp Code extension!

Robocorp Code extension UI

  • Click the monkey icon. A ROBOCORP CODE panel opens.
  • In the ROBOTS section, click my-rsb-robot.
  • Hover your mouse cursor over Run all tasks and click the Launch Task icon on the right. It looks like a play button.

The robot starts running!

The run might take a bit of time the first time you do it. An execution environment will be automatically set up for your robot based on the contents of the conda.yaml configuration file. Subsequent runs are much faster since the environment is already set up. Neat!

The environment consists of many small files, and if you happen to have a virus scanner on your machine (for example, Windows Defender), it will probably want to take a look at all those files, which will add to the waiting time. 🔎

The TERMINAL panel

You will see a lot of things happening in the TERMINAL panel at the bottom right of your VS Code screen. Eventually, you should see something like this in the terminal output:

============================================================================== Tasks :: Template robot main suite. ============================================================================== Minimal task | PASS | ------------------------------------------------------------------------------ Tasks :: Template robot main suite. | PASS | 1 task, 1 passed, 0 failed ==============================================================================

PASS means the task completed successfully. Before diving in deeper into the results of the run, let's see the keyboard-way-of-running-things.

Run the robot using your keyboard

Learning keyboard shortcuts is a skill that saves you time and helps you complete things faster.

VS Code provides a helpful tool called Command Palette. It's a handy helper that lets you quickly find and run any command you need - including running your robot!

Running the robot from the Command Palette

  • Open the Command Palette by pressing Shift-Command-P (macOS) or Ctrl+Shift+P (Windows).
  • Type run robot. This will find the command you need.
  • Press Enter to run the Robocorp: Run Robot command.

The Command Palette will remember the last command you ran. This is super handy when you want to run your robot many times when testing it. Just open the Command Palette and press Enter. The last ran command will be executed! Warp Speed, Scotty! 🚀

View the task log

Your robot writes a detailed log of everything it did during the execution of the task. There are a few ways to find and view the log.

Opening the log from the terminal panel

In the TERMINAL panel, the last line of the output is the path to the log file. You can open it in your default browser by holding Command (macOS) or Ctrl (Windows) and left-clicking the path with your mouse.

Leave the browser window/tab open. Refresh the window anytime you want to see the latest log output.

Optional: Finding the log file in file system

You can skip this part for now! It is still good to know where to find the actual log file if you happen to need it!

You can find the log file from the Explorer panel (click on the Explorer icon in the vertical toolbar - it's the topmost one that looks like a bunch of documents).

Click the output folder. You will find files. The log.html file is an HTML file you can view in any web browser.

log.html in the output folder

Optional: Installing a VS Code web browser extension to open HTML files

You can skip this part and return to it if you find you want to open any HTML files in browser!

VS Code does not provide a default way to open an HTML file in a web browser. To add this functionality, install the open in browser extension.

Similar to the Robocorp Code extension, the open in browser extension, well, extends, the capabilities of VS Code by adding support for new functionality. There is an extension available for practically anything you need! If you know and prefer some other web browser extensions, you can use those, too!

After installing the open in browser extension, right-click on the log.html file and select Open In Default Browser. The log file will be opened in a new browser window or a tab.

View the log in browser

In the log file, under the "Task Execution Log" heading, you will see a line "SUITE Tasks". Hover your mouse cursor over the line and click the icon (Expand all) on the right to expand the complete log.

Log file contents

On the last line in the log, you see "Done.".

Hurray! Our project is almost done! 😀

Anatomy of your robot 🤖

What are small robots made of? Of settings, tasks, and keywords, mostly! These are placed in sections.

*** Settings *** Documentation Template robot main suite. *** Tasks *** Minimal task Log Done.

This robot has two sections for now. The *** Settings *** section typically contains documentation, possibly some libraries, and references to other files. This robot contains only documentation.

The *** Tasks *** section defines the tasks for the robot. This robot has one task (it could have many). The name of the task is Minimal task.

To complete the task, the robot calls the Log keyword. Think of keywords as functions if you are familiar with programming. Keywords provide the robot with specific skills. In this case, writing to the log. The Log keyword takes one argument. In this case, the argument is the text we want the robot to write to the log (Done.).

"Hey keyword! Take this argument and do something useful with it!"

We'll discuss the robot anatomy in more detail in the next chapter, where you will teach your robot to open the RobotSpareBin intranet in a web browser.

What we learned

  • A robot is made of one or many suites, which then contain tasks, user keywords and other assets.
  • You can run your robot from the user interface or using your keyboard.
  • An execution environment is automatically created based on the conda.yaml configuration file when the robot is run. The environment is cached, meaning that using the same environment is super-fast after it has been created once!
  • When you run your robot, a detailed log file is created.
  • You can open the log in your default browser by holding Command (macOS) or Ctrl (Windows) and left-clicking the log file path in the terminal pane with your mouse.
  • Robot files consist of sections, each with a specific purpose.
  • Keywords are like functions in other programming languages, and they can accept arguments.
  • Robot syntax is human-readable!
  • VS Code with the Robocorp Code extension provides all-the-things needed for creating robots.
  • You can add functionality to VS Code by installing extensions.
  • Keyboard shortcuts save you time and help you complete things faster.
  • Determining the average air speed velocity of a laden swallow is complicated. 🕊