Skip to content

Defining Global Objects

Note

This feature requires Rapise 6.6+

Why

If you are building a framework and write custom functions in JavaScript you may combine the functions and define a global object. It will make RVL more readable and easier to write.

Compare variants A and B.

RVL Example

In variant A you choose Functions as an object and then select the custom function. In variant B you choose the global object and then it's action. The global object and it's actions can be seen in the Object Tree:

Object Tree

How

Let's see how to define your own global object.

First, you need a JavaScript file where you will define the actions of the object and declare the object itself. A good candidate for such a file is the main file of a user-defined library or simply User.js.

We'll use an example to explain the format of object definition. Here is the definition of a global object MyApp.

Example

// MyApp definition
// to generate metadata press Ctrl-Shift-F5

function MyApp_Launch()
{

}

function MyApp_Close()
{

}

function MyApp_Login(/**string*/ username, /**string*/ password)
{
    Tester.Message("Logging as " + username + "/" + password);
}

_paramInfoMyApp_Login = {
    _description: "Logs into the application",
    _type: "boolean",
    _returns: "`true` if login is ok",
    username:
    {
        description: "Name of the user"
    },
    password:
    {
        description: "Pwd of the user"
    }
}

SeSGlobalObject("MyApp");

Format

Every action of MyApp object is prefixed with MyApp_. We have three such actions: Launch,Close and Login.

function MyApp_Launch()
{

}

function MyApp_Close()
{

}

function MyApp_Login(/**string*/ username, /**string*/ password)
{
    Tester.Message("Logging as " + username + "/" + password);
}

To declare the object use SeSGlobalObject call. It must be placed after definitions of all the actions.

SeSGlobalObject("MyApp");

You may specify action parameter types through comments /**<type>*/.

function MyApp_Login(/**string*/ username, /**string*/ password)

You may also describe actions and parameters using paramInfo objects (should have a name of format _paramInfo<action function name>).

_paramInfoMyApp_Login = {
    _description: "Logs into the application",
    _type: "boolean",
    _returns: "`true` if login is ok",
    username:
    {
        description: "Name of the user"
    },
    password:
    {
        description: "Pwd of the user"
    }
}

Compile Metadata

When the object is declared you need to compile the metadata for it. To do this open the file where you defined the object and press Ctrl+Shift+F5.

Object Icons

If you want a specific icon for your object then create two .png files with dimensions 16x16 and 32x32, name them as <object name>16.png and <object name>32.png and place them beside the file where you declared the object.

See Also