Dynamically Changing the Report Directory in TestStand

Updated Jan 19, 2023

Environment

Software

  • TestStand

This article demonstrates how to programmatically configure the output directory of a TestStand report at run-time. The steps below indicate how to change the report directory based on:
  1. A specific and static directory.
  2. The value of a local variable.
  3. An expression including macros that is evaluated at run-time.

To change the report directory programmatically:


1. Override the ReportOptions Callback in your test sequence.

  • Right-click on the Sequences Pane and selecting Sequence File Callbacks.
  • In the pop-up window, place a checkmark next to ReportOptions and click OK.
  • Click on the ReportOptions sequence to open it.
2. Place a Statement Step inside the ReportOptions sequence.
  • From the Insertion Palette, drag and drop a Statement on the sequence.
3. To set the report directory to a specific folder:
  • Define a value for ReportOptions.Directory and set ReportOptions.DirectoryType to SpecificDirectory, as shown below.
  • Note: replace <your custom directory> with your target directory.


Parameters.ReportOptions.Directory = <your custom directory>,
Parameters.ReportOptions.DirectoryType = "SpecificDirectory"

 

  • The complete Statement should resemble the following image.

RepotOptions Specific Directory.PNG


4. To switch the destination directory based on a variable:

  • From the Insertion Palette, navigate to Flow Control >> If. Place an If and Else Statement before overriding the ReportOptions parameters.
  • Specify a condition that overrides ReportOptions.Directory based on a variable value, as shown below.


 

5. To set the report directory based on an expression:

  • In the Variables Pane, expand StationGlobals and right-click to create a new String Variable called ReportDirectory.
  • In the ReportOptions Statement Step, assign the current sequence file directory to StationGlobals.ReportDirectory as shown below.
StationGlobals.ReportDirectory = Left(RunState.SequenceFile.Path, Find(RunState.SequenceFile.Path, "\\", 0, False, True)),
  • Depending on the Model being used, set a value for ReportFileSequentialModelExpression or ReportFileBatchModelExpression using macros.
  • The example below demonstrates how to construct a directory based on the client sequence file name, UUT serial number, current time and current date.
Parameters.ReportOptions.ReportFileSequentialModelExpression = "StationGlobals.ReportDirectory + \"\\\\$(ClientFileName)_Test_Results\" + \"\\\\$(ClientFileName)_Report[$(UUT)][$(FileTime)][$(FileDate)]$(Unique).$(FileExtension)\"",
  • The complete Statement should resemble the following image.
ReportOptions Parameters.png


Additional Information


Depending on your specific situation, you can add this code in two different places:
If you wanted to save the report to the directory containing your client sequence file, you get the path of the client file from the RunState.Root.RunState.ProcessModelClient.Path variable. Note that this variable is only available at runtime.

Attached is an example file which demonstrates modifying the report directory using the ReportOptions Callback sequence.