Difference between revisions of "Studio:Debugging Helps"

From STRIDE Wiki
Jump to: navigation, search
m
 
(13 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= Script Debugging Techniques =
+
= Script Debugging Helps =
 
Listed here are some simple debugging techniques that will aid in understanding and troubleshooting scripts that drive STRIDE tests.
 
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() ==
 
== PrintMessage() ==
  
The studio object provides a way to perform printf-style debugging of scripts running within STRIDE Studio.
+
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.
 
PrintMessage allows you to log messages from running scripts and view the values of variables during script execution.
Line 13: Line 11:
 
Here's an example of its use in a perl script:
 
Here's an example of its use in a perl script:
  
<pre>
+
<source lang="perl">
 
my $funcs = $main::ascript->Functions;
 
my $funcs = $main::ascript->Functions;
  
Line 22: Line 20:
 
   $main::studio->Output->PrintMessage("function item ".$_." ".$f->Name);
 
   $main::studio->Output->PrintMessage("function item ".$_." ".$f->Name);
 
}
 
}
</pre>
+
</source>
  
 
=== JScript example ===
 
=== JScript example ===
 
Here's and example of its use in JScript:
 
Here's and example of its use in JScript:
  
<pre>
+
<source lang="javascript">
 
var funcs = ascript.Functions;
 
var funcs = ascript.Functions;
  
 +
// loop through each captured function
 
for (var i = 0; i < funcs.Count; i++)
 
for (var i = 0; i < funcs.Count; i++)
 
{
 
{
 
     var f = funcs.Item(i);
 
     var f = funcs.Item(i);
 +
    // send output to Studio Messages window
 
     studio.Output.PrintMessage("function item " + i + " " + f.Name);
 
     studio.Output.PrintMessage("function item " + i + " " + f.Name);
 
}
 
}
</pre>
+
</source>
  
 +
=== Sample Output ===
 
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.
 
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.
  
<center>
+
 
[[Image:PrintMessageOutput.jpg]]
+
[[Image:PrintMessageOutput.jpg|frame|none|Sample PrintMessage() Output]]
</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.
  
 +
=== perl example ===
 
Here's an example of its use in a perl script:
 
Here's an example of its use in a perl script:
  
<pre>
+
<source lang="perl">
 
my $funcs = $main::ascript->Functions;
 
my $funcs = $main::ascript->Functions;
  
Line 58: Line 59:
 
                               "Debug Output");
 
                               "Debug Output");
 
}
 
}
</pre>
+
</source>
  
 
=== JScript example ===
 
=== JScript example ===
 
Here's an example of its use in JScript:
 
Here's an example of its use in JScript:
  
<pre>
+
<source lang="javascript">
 
var funcs = ascript.Functions;
 
var funcs = ascript.Functions;
  
 +
// loop through each captured function
 
for (var i = 0; i < funcs.Count; i++)
 
for (var i = 0; i < funcs.Count; i++)
 
{
 
{
 
     var f = funcs.Item(i);
 
     var f = funcs.Item(i);
 +
    // send output to the Studio Messages window
 
     ascript.MessageBox("function item " + i + " " + f.Name,
 
     ascript.MessageBox("function item " + i + " " + f.Name,
 
                       "Debugging output");
 
                       "Debugging output");
 
}
 
}
</pre>
+
</source>
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.
+
 
 +
=== Sample Output ===
 +
The displayed message box can be customized in several ways; see [[AutoScript]] for details. Shown below is output from the sample script.
 +
 
  
<center>
+
[[Image:MessageBoxOutput.jpg|frame|none|Sample MessageBox() Output]]
[[Image:MessageBoxOutput.jpg]]
 
</center>
 
  
 
= Exception Messages =
 
= 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.
 
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.
  
<center>
+
Below is a sample of the dialog that's shown when an exception occurs (and the exception is not caught by the script).
[[Image:ExceptionDialogExample.jpg]]
+
 
</center>
+
 
 +
[[Image:ExceptionDialogExample.jpg|frame|none|Sample uncaught exception dialog]]
 +
 
 +
 
 +
This behavior is the default in '''JScript'''.
 +
 
 +
''This is not the case in '''perl'''''. To ensure that these errors are seen by your perl script, be sure to follow the  [[How_do_I_get_Perl_scripts_to_emit_fatal_errors_when_a_COM_error_occurs%3F|recommendation here]].
  
To ensure that these errors are seen by your perl script, be sure to follow the  [[How_do_I_get_Perl_scripts_to_emit_fatal_errors_when_a_COM_error_occurs%3F|recommendation here]].
+
[[Category:Studio:Troubleshooting]]

Latest revision as of 17:36, 20 August 2009

Script Debugging Helps

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

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;

// loop through each captured function
for (var i = 0; i < funcs.Count; i++)
{
    var f = funcs.Item(i);
    // send output to Studio Messages window
    studio.Output.PrintMessage("function item " + i + " " + f.Name);
}

Sample Output

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.


Sample PrintMessage() Output

MessageBox()

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

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::ascript->MessageBox("function item ".$_." ".$f->Name,
                              "Debug Output");
}

JScript example

Here's an example of its use in JScript:

var funcs = ascript.Functions;

// loop through each captured function
for (var i = 0; i < funcs.Count; i++)
{
    var f = funcs.Item(i);
    // send output to the Studio Messages window
    ascript.MessageBox("function item " + i + " " + f.Name,
                       "Debugging output");
}

Sample Output

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


Sample MessageBox() Output

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.

Below is a sample of the dialog that's shown when an exception occurs (and the exception is not caught by the script).


Sample uncaught exception dialog


This behavior is the default in JScript.

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