Studio:Debugging Helps: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 43: Line 43:
</center>
</center>


=== MessageBox() ===
== MessageBox() ==
The ascript object provides a way to interrupt script execution and display a modal message box containing a message you specify.
The ascript object provides a way to interrupt script execution and display a modal message box containing a message you specify.


Line 60: Line 60:
</pre>
</pre>


=== JScript example ===
Here's an example of its use in JScript:


Here's an example of its use in JScript:
<pre>
var funcs = ascript.Functions;


for (var i = 0; i < funcs.Count; i++)
{
    var f = funcs.Item(i);
    ascript.MessageBox("function item " + i + " " + f.Name,
                      "Debugging output");
}
</pre>
The displayed message box can be customized in several ways; see online help and autosense for details. Shown below is output from the sample script.
The displayed message box can be customized in several ways; see online help and autosense for details. Shown below is output from the sample script.



Revision as of 23:43, 4 February 2008

Script Debugging Techniques

Listed here are some simple debugging techniques that will aid in understanding and troubleshooting scripts that drive STRIDE tests.

As you work through the training scripts, you may find it helpful to insert one or more of the following debugging helps as an aid in understanding the flow of execution or to investigate the value of variables and expressions as the script runs.

PrintMessage()

The studio object provides a way to perform printf-style debugging of scripts running within STRIDE Studio.

PrintMessage allows you to log messages from running scripts and view the values of variables during script execution.

perl example

Here's an example of its use in a perl script:

my $funcs = $main::ascript->Functions;

# loop through each captured function
foreach (0..($funcs->Count - 1)) {
   my $f = $funcs->Item($_);
   # send output to Studio Messages window
   $main::studio->Output->PrintMessage("function item ".$_." ".$f->Name);
}

JScript example

Here's and example of its use in JScript:

var funcs = ascript.Functions;

for (var i = 0; i < funcs.Count; i++)
{
    var f = funcs.Item(i);
    studio.Output.PrintMessage("function item " + i + " " + f.Name);
}

Note that the single argument to the PrintMessage() function will accept any expression that perl can interpret as a string. Shown below is output from the sample script.

PrintMessageOutput.jpg

MessageBox()

The ascript object provides a way to interrupt script execution and display a modal message box containing a message you specify.

Here's an example of its use in a perl script:

my $funcs = $main::ascript->Functions;

# loop through each captured function
foreach (0..($funcs->Count - 1)) {
   my $f = $funcs->Item($_);
   # send output to Studio Messages window
   $main::ascript->MessageBox("function item ".$_." ".$f->Name,
                              "Debug Output");
}

JScript example

Here's an example of its use in JScript:

var funcs = ascript.Functions;

for (var i = 0; i < funcs.Count; i++)
{
    var f = funcs.Item(i);
    ascript.MessageBox("function item " + i + " " + f.Name,
                       "Debugging output");
}

The displayed message box can be customized in several ways; see online help and autosense for details. Shown below is output from the sample script.

MessageBoxOutput.jpg

Exception Messages

Most calls to STRIDE scripting objects will throw an exception to indicate that an error has occured. The descriptions that accompany these exceptions can be very helpful in identifying the source of the error and correcting it.

ExceptionDialogExample.jpg

To ensure that these errors are seen by your perl script, be sure to follow the recommendation here.