Knowledge Base

  1. Home
  2. Knowledge Base
  3. Technical Support
  4. Script Commands
  5. Including Assets in scripts

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 maintainance 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.

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 continous integration processes

include()

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

Arguments:

NameTypeDescription
asset namestringThe name of the asset to include

Code example:

Lets say I have an asset named “utils” with the following code written inside it:

//Agenty 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);
        });
}

I can now write the following inside my test script:

client.include(utils)

client
    .url(url)
    .waitForElementVisible('body', 30*sec);

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 fuctions that wotk 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 scipt only, before doing anything else

Was this article helpful?

Related Articles

Leave a Reply 0 comments

Leave a Reply: