Adding JavaScript rules

When you have a JavaScript file with defined rules to create values for any item type, then you can add the JavaScript rules to create the values for the mapped item type.

Before you begin

  • You must have created a project and a schema.
  • You must have created a JavaScript file with defined rules in your local file system.

About this task

If you want to add the JavaScript rules to create the values for the mapped item type, then you must use the following command to define the rules in the JavaScript file:

function getData()

You can additionally set any one of the following properties for the mapped item type by using the JavaScript rules:

  • Regular expression: The JavaScript rule uses the regular expression that you enter in the Properties dialog box as an input for the regular expression rule.
  • Seed value: The JavaScript rule uses the seed value that you enter in the Generate Data dialog box as an input for the seed value rule.

To set either regular expression or seed value property, you must define the rules in the JavaScript file by using the following commands:

Property Command Parameter description
Regular expressions function getData(param) (param): Represents the regular expression pattern in the Regular Expression field.
Seed value function getData(param) (param): Represents the seed value in the Numeric Seed Value field of the Generate Data dialog box.
Note: If you set the values for both regular expression and seed value properties in HCL OneTest Data and define the rule in the JavaScript file by using the command function getData(param), then only the value set for regular expression property is accepted while creating the item type values.

After you define rules in the JavaScript files, you can import the JavaScript file from your local file system into your project, and then map the file to any item type in a schema.

Procedure

  1. Select the project in HCL OneTest Server and go to the Data Fabrication page.
  2. Click Files and import the JavaScript file from the local file system into your project.
  3. Open your schema from the Schemas tab.
  4. Select the item type for which you want to create the values by using the JavaScript file.
  5. Select Item Properties from the drop-down list of the Properties dialog box.
  6. Select Text in the Item Subclass field.
  7. Click the Advanced Properties icon -.
  8. Optional. Provide the pattern in the Regular Expression field, if you want to set the regular expression for the mapped item type.
  9. Provide the name of the JavaScript file with an extension in the JavaScript Name field.
    Important: You must enter the correct file name of the JavaScript file that you imported into your project. For example, address.js.
  10. Click Save.

Results

You have successfully added the JavaScript rules for the item type.

What to do next

You must prepare the structural view of the schema. See Designing a structural view of the schema.