Let's start by looking at the code required to execute the robot
NewsMagazine.robot, which is located in the Tutorials folder of the
default project. The robot outputs its results using the Return Value step action,
which makes it easy to handle the output programmatically using the API. Other robots (typically those run
in a schedule
by the Management Console)
store their data directly in a database using the Store in Database step action,
in which case data collected by the robot will not be returned to the API client.
In the following, we will look at how to execute the NewsMagazine robot and process the output programmatically.
Execute a Robot without input
Let's start by looking at the classes involved and their responsibilities.
||This is a simple value object that identifies a RoboServer which can execute robots. Each RoboServer must be activated by a Management Console and assigned KCU before use.|
||A cluster is a group of RoboServer functioning as a single logical unit.|
||This class is used to construct the robot request. Before you can execute any requests you must register a cluster with the Request class.|
||A robot library instructs RoboServer where to find the robot identified in the request. Later examples will explore the various robot library types and when/how to use them.|
||This contains the result of a robot execution. The result contains value responses, log and server messages.|
||Each value that is returned from a robot using the Return Value action can be accessed as an RQLObject.|
Now let's go through each line in the example an look at the specifics.
The first line tells the API that our RoboServer is running on localhost port 50000.
The next three lines defines a cluster with a single RoboServer. The cluster
is registered with the
Request class, allowing you to
execute request on this cluster. Each cluster may only be registered
once per application, this is usually done during the initialization of the application.
Registering a cluster
This is then followed by code that creates a request that will execute the robot named
NewsMagazine.robot located at
refers to the robot Library configured for the request. Here the
DefaultRobotLibrary is used, which instructs RoboServer to
look for the robot in the servers local file system, see Robot Libraries for details on how to use robot
The next line executes the robot on the cluster named
MyCluster (the cluster we previously registered) and
returns the result once the robot is done. If an error occurs while the robot is executing an exception will
be thrown here.
Finally we process the extracted values. First we get all extracted values of the type named Post, and iterate through them. For each RQLObject we access the attributes of the Post type, and print the result. We will look at attributes and mappings in a later section.