The steps for creating a common library are as follows:

  1. Create a new Rapise test using the "New Test" option.
  2. Call this test "Common.sstest". This will hold the common functions and objects
  3. Use the REST Editor to create the various objects and methods that will be part of the library.
  4. These objects will be saved in Common.objects.js
  5. Put any common library functions in the Common.user.js file
  6. Finally add the following special function in the Common.user.js file:
function LoadObjects() {
    var objectsPath = Global.GetFullPath('..\\Common\\Common.objects.js');
    var saved_script_objects = {};
    if (objectsPath) {
        if (g_helper.FileExists(objectsPath)) {
            eval(g_helper.Include(objectsPath));
        }
        else {
            throw 'Unable to find object file at ' + objectsPath;
        }
    }
    else {
        return null;
    }

    // Push list of saved_script_objects to the end of the stack
    g_object_info_map.push(saved_script_objects);
    for (var obj_name in saved_script_objects) {
        var obj = saved_script_objects[obj_name];
        if (obj.window_name && obj.object_type == 'RESTService') {
            obj.window_name = '..\\Common\\' + obj.window_name;
        }
    }
    return saved_script_objects;
}

g_load_libraries = ["Web Service"];

 

Now close this "Common.sstest" common Rapise test library and start a new test script (e.g. called Test1.sstest). This test will have its own objects file (Test1.objects.js) and user functions file (Test1.user.js).

Now in the "Test Files" tab, right-click on the "Scripts" folder and choose the option to "Add File(s)...". Change the filetype from "*.js" to "*.sstest" and include the Common.sstest file. You should now have the following test hierarchy:

If you right-click on the "Common.sstest" icon and choose "Show Objects", the objects from the included common library will be displayed in the "Object Tree" tab along with the objects from the individual test script (Test1).

Now to include these common functions and libraries in your test (e.g. Test1.sstest) you just need to include some commands at the beginning of the main Test() entry point:

function Test() {
    //Load the shared objects
    eval(g_helper.Include('..\\Common\\Common.user.js'));
    LoadObjects();

    //Call a shared REST request
    SeS('Common_New_Request').DoExecute(null);
    Tester.Message(SeS('Common_New_Request').GetResponseBodyObject());
}

These lines with the DoExecute() and Tester.Message() are just an example of using one of the shared REST web service objects.