TSL stands for Test Script Language. It is created by Mercury Interactive.
Syntax Rules of TSL
- Semi‐colons mark the end of a simple statement.
- Statements that contain other statements are called compound statements. Compound statements use curly braces and not semi‐colons.
- TSL is a case sensitive language. You need to be extra careful with the case of the statements. Most of the identifiers, operators and functions within the language utilize lower case so use lower case when you are not sure.
What Constitutes TSL?
Comments :Use a # symbol to write a comment. Statements written as comments are ignored by the interpreter. It makes easier for the reader of the test script with useful information about the test. TSL does not have multi‐line comments.
Naming Rules :Every language has rules that define what names are acceptable in the language and which names are not. Naming rules of TSL are :
- Must begin with a letter or the underscore.
- Cannot contain special characters except the underscore.
- Cannot match a reserved word.
- Must be unique within a context.
- Case Sensitive.
Data Types :When a script is executing, different kinds of data gets stored. TSL simply uses the context in which we access the data to determine what the data type is. There are two data types in TSL:
- String : stores alphanumeric data.
- Number : Stores numeric data.
Data Storage : This refers how information is stored in the test during test execution. TSL uses three different types of storage vehicles. These include :
- Variables : for dynamic storage.
- Constants : for fixed values.
- Arrays : for sets.
Variables :Variables are used to capture the information that is to be needed later to be stored temporarily. In TSL, variable declaration is optional so you can create a variable simply by using the variable in your code. The only exception to this is in functions.
Constants :Constants are very similar to variables because they store values also. The major difference between these two is that the value of a constant is fixed and cannot be changed during code execution.
Arrays :Arrays are used to store several pieces of related data such as names. TSL provides a better mechanism for use when dealing with a collection of similar items. This concept, known as arrays, allows you to store several values of related information into the same variable.
Operations :Operations are the many forms of computations, comparisons etc that can be performed in TSL. The symbols used in an operation are known as operators and the values involved in these operations are known as operands.
Branching :Branching statements allow your code to avoid executing certain portions of code unless a specified condition is met. TSL uses two kinds of branching statements i.e. the if statement and the switch statement.
Loops :Loops provide the ability to repeat execution of certain statements. These statements are repeatedly executed until an initial condition evaluates to false. TSL supports four different types of loops and these are the while, do..while, for and for..in loops.
Functions :Functions are blocks of code containing one or more TSL statements. These code blocks are very useful in performing activities that need to be executed from several different locations in your code. TSL provides many built in functions as well as provides you the ability to create your own user‐defined functions.