Here are some common problems that occur with scripts.
It is very easy to make typographical errors that the 4Test compiler cannot catch. If a line of code does nothing, this might be the problem.
When you write a function that uses global variables, make sure that each variable has an appropriate value when the function exits. If another function uses the same variable later, and it has an unexpected value on entry to the function, an error could occur.
To check that a variable has a reasonable value on entry to a function, set a breakpoint on the line that calls the function and use the commandto check the variable's value.
Silk Test Classic does not initialize variables for you. So if you have not initialized a variable on entry to a function, it will have the value <unset>. It is better to explicitly give a value to a variable than to trust that another function has already initialized it for you. Also, remember that 4Test does not keep local variables around after a function exits; the next time the function is called, its local variables could be uninitialized.
If you are in doubt about whether a variable has a reasonable value at a particular point, set a breakpoint there and useor to check the variable's value.
It is usually not good programming practice to give different variables the same names. If a global and local variable with the same name are in scope (accessible) at the same time, your code can only access the local variable.
To check for repeated names, useand to see if two variables with the same name are in scope simultaneously.
When you write a for loop or a while loop, be sure that the initial, final, and step values for the variable that controls the loop are correct. Incrementing a loop variable one time more or less than you really want is a common source of errors.
To make sure a control loop works as you expect, useInto to step through the execution of the loop one statement at a time, and watch how the value of the loop variable changes using .
The order in which 4Test applies operators when it evaluates an expression may not be what you expect. Use parentheses, or break an expression down into intermediate steps, to make sure it works as expected. You can use View/Expression to evaluate an expression and check the result.
A break statement transfers control of the script out of the innermost nested for, for each, while, switch, or select statement only. In other words, break exits from a single loop level, not from multiple levels. UseInto to step through the script one line at a time and ensure that the flow of control works as you expect.
To check for infinite loops, step through the script with.
To check for code that never executes, step through the script with.