Knowledge Base Article

> Knowledge Base > Rapise

Created By  alexey.grinevich Wednesday, November 29, 2017

Sometimes it is useful to have common functionality and variables in a separate JavaScript source file. This topic explains the steps to do it.

How to store common functions in a separate .js file

Suppose you have common functions and variables that needs to be re-used across different tests.

Here we explain how to include them in your test. Suppose that we have a file CommonUtils.js with a function GetHostInfo(). The function puts information about OS and current user into the report.

Prepare folder structure

We assume that common files are stored in folder:

Folder

Include common JS in test

  1. Switch to 'Files' tab.

Files Tab

  1. Right-click on the 'Test' node and choose 'Add File(s)...':

Add File

  1. Now choose a common file. It becomes a part of the test:

File in Test

  1. Now Open "Functions" file in the code editor:

Functions Toolbar

  1. Drag common file from the tree:

Drag Start

To the empty line in the code editor:

Drag End

  1. Now you may use a function from CommonUtil.js from RVL: Common function RVL

or from JavaScript:

function Test()
{
    GetHostInfo();
    
    // Do the rest
    
}

About common file

Common file may contain functions and variables. If functions refer to Objects or contain object actions then different approach should be used (see Include subtests).

Please, note that common JS file should not contain overrides for base prototype (Object.prototype and Array.prototype).

Attachments

Selected files will be attached to any email sent on saving ticket.

file selected files selected  () Delete Selected

  • Created:
  • by:

Select files to upload

Or drag and drop files here

Uploading …
Done!
Upload More?
There was an error.
Try again?

Save to upload the selected file(s)

Article Info
  • Last Updated: 11/29/2017
  • Article ID: KB308
  • Views: 51