Skip to main content

Including Assets in scripts

testRTC has the ability to store code assets and then use them inside your test scripts by a dedicated include command. This is useful when you are maintaining a large set of scripts, each offering different scenario within your application or when you need to run multiple monitors with slight variations.

Assets

You can find the Assets of your testRTC project in the sidebar or by following this link.

Currently, the only asset type supported is code, and can be used to store script functions and variables:



  • The Asset Name will be used to indicate which one to include (more on that later)
  • The Description is a verbose description for your maintenance purposes
  • Asset Type is always Code (for now)
  • The Version field enables you to manage versions on your end. testRTC makes no use with this field
  • The Code is the script itself
Note:

A few notes:

  • You can create multiple Assets and include multiple assets in your test scripts as you see fit
  • You can use the testRTC APIs to add, edit and delete assets as part of your continuous integration processes

include()

To include an Asset inside a test script you can use the client.include() script command.

Arguments
Name Type Description
asset name string The name of the asset to include

Code example

Lets say I have an asset named “utils” with the following code written inside it:
// Agent type conversion
var probeType = Number(process.env.RTC_IN_SESSION_ID);
var sec = 1000;
var url = process.env.RTC_SERVICE_URL;

function switchWindow(value) {
    client
        //.rtcScreenshot('before switch')
        .pause(10 * sec)
        .windowHandles(function(result) {
            var newWindow;
            newWindow = result.value[value];
            this.switchWindow(newWindow);
        });
}
You can now write the following inside my test script:
client.include('utils')

client
    .url(url)
    .waitForElementVisible('body', 30*sec);
Note: In the example above, the url and sec variables were defined in the utils asset.

Best Practices

Here are a few best practices to get you going with assets:

  • Create separate assets for general variables and utilities and for actual functions that work with the DOM of your service
  • If you are using users and passwords, place them in a ‘users’ asset and include where needed
  • Include all of your assets at the beginning of the test script only, before doing anything else

Was this article helpful?

0 out of 0 found this helpful