1 / 31

Test Script Language

Test Script Language. What is TSL. Proprietary language owned by HP/Mercury for use in their testing tools Heavily based on the C language and is very similar to Perl and JavaScript Interpreted Loosely-typed Implicitly declared (except in functions). Contents. Syntax Rules Naming Rules

Download Presentation

Test Script Language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Test Script Language

  2. What is TSL • Proprietary language owned by HP/Mercury for use in their testing tools • Heavily based on the C language and is very similar to Perl and JavaScript • Interpreted • Loosely-typed • Implicitly declared (except in functions)

  3. Contents • Syntax Rules • Naming Rules • Comments • Data Types • Storage • Variables • Constants • Operators • Arithmetic • Comparison • Logical • Assignment • Concatenation • Branching • if • Looping • while • do…while • for

  4. Syntax Rules • TSL is case sensitive • Statements can be either simple statements or compound statements • Simple statements are terminated with a semi-colon (;). • Compound statements are marked by { } (open and close curly braces

  5. Naming Rules • Must begin with a letter or the underscore • Good: count, strInfo, _data • Bad: 2day, 4get, *count violate this rule. • Cannot contain special characters except the underscore • Good: Names using alphabets, numbers and the underscore. • Bad: Names using symbols and other special characters. • Cannot match a reserved word • Bad: for, if, Select • Must be unique within a context • Must be less than 48 characters • Names are case sensitive • You can have 3 variables named Data, data & DATA in the same test

  6. Naming Convention objDescriptiveName • obj • Three letter prefix for the data type • DescriptiveName • A descriptive name for the variable • First letter of each word in upper case

  7. Comments # This is a comment • Comments can be full line or partial line • Comments do not need to end with a ;

  8. Literal Types • Numeric • 1 • 3.14 • 3E7 • String • “Hello World” • “123 Straw Lane” • “43210” • Boolean values are treated as numbers • True is represented as 1 • False is represented as 0

  9. Variables staticvariableName; autovariableName; publicvariableName; externvariableName; • Variables hold values that can change during program execution • They function just like temporary storage locations

  10. Constants const constantName=value; • Constant names hold values that cannot change during program execution • Constants should be used in place of hard-coded values

  11. Operations • Operations are the many forms of computations, comparisons etc that can be performed in the language • Most operations are binary using the form: operand1 operator operand2 • Two operations are unary using the form operator operand1 • One operation is tertiary using the form operand1 operator operand2 operator operand3 • When an operator has 2 symbols, you cannot separate them with a space: • Good: 2 != 3 • Bad: 2 ! = 3

  12. Arithmetic • Used to perform calculations • Both operands must be numeric values • The result is a numeric value

  13. Comparison • Used to compare the value of two items • Both operands must be of the same data type • The result is a Boolean value

  14. Logical • Used to reduce Boolean values into a single Boolean value • Both operands must be Boolean values • The result is a Boolean value

  15. And (&&) Truth Table • Conjunction • Used when both conditions are required

  16. Or (||) Truth Table • Disjunction • Used when either condition is sufficient

  17. Not (!) Truth Table • Unary Operand • Used to change the value of a condition

  18. Assignment • Changes the value of a variable • = • Several shortcut forms exist:

  19. Concatenation • Combines 2 data types for display as a string • &

  20. Branching • Allows you to avoid running certain sections of your code • Code is only executed when a condition (or conditions) evaluate to True • Provides a single application the ability to react differently to different input values

  21. if If (condition) { statement(s); } • Performs an operation only if the condition evaluates to True • Used when an action is either performed or not performed.

  22. if…else if (condition){ statement(s); } else { statement(s); } • Performs the If portion only if the condition evaluates to True and the Else portion otherwise. • Used in an either or scenario when an operation is always performed.

  23. if…else..if if (condition1){ statement(s); } else if (condition2){ statement(s); } else { statement(s); } • Only one section can be executed even if many conditions evaluate to True. • Used in a multiple choice scenario • Inclusion of the last Else is optional

  24. Loops • Allows you to repeat running certain sections of your code • Code executes when a condition (or conditions) evaluate to True • Be careful with Loops. They can result in infinite processing. • Forms • Entry Condition • Entry only when a initial condition is met • Exit Condition • The loop is always executed at least once • Iterated • Repeats for a specific number of times

  25. Loop Questions • Can this loop ever be entered • If no, then you don’t need the loop • Can this loop ever be exited • If no, then you have an infinite loop

  26. while while (condition) { statement(s); } • Entry Condition Loop • Simplest form of the loop • Requires manual modification of the loop condition

  27. do..while do { statement(s); } while (condition); • Exit Condition Loop • Requires manual modification of the loop condition

  28. for for (variable = start; condition; modifier) { statement(s); } • Iterated Loop • Favored because all the loop details are in the definition statement

  29. Functions function FunctionName(parameters) { statement(s); } • Allow you to define a set of operations • Must be defined before they are invoked

  30. Exercise 1 Convert the following VBScript code to TSL ‘Declare a variable Dim numData Const PI = 3.142 ‘Use create_input_dialog instead of InputBox numData = InputBox(“Please enter a radius”) numAnswer = PI * (numData ^ 2) ‘Use pause instead of Msgbox ‘In TSL, the () is mandatory Msgbox “The area of a circle of radius “ & numData & “ is “ & numAnswer

  31. Exercise 2 Convert the following TSL code to VBScript static numData; numData = create_input_dialog(“Enter a number”); numDouble = numData * 2; numSquare = numData ** 2; strAnswer = “The double of “ & numData & “ is “ & numDouble; #Use vbCrLf instead of \n strAnswer = strAnswer & “\n”; strAnswer &= “The square of “ & numData & “ is “ & numSquare; pause(strAnswer);

More Related