To download NI software, including the products shown below, visit ni.com/downloads.
The TestStand Application Manager supports processing custom command line arguments through the ProcessUserCommandLineArguments event. This can prove useful when automating test execution from a CI server.
This example is similar to the .NET Basic User Interface, but has been modified to accept the following command line arguments:
Option | Purpose |
---|---|
/SimulateFailure <failures> | When used with the included example sequence file, this suppresses the simulation dialog and instead simulate failures as specified. This argument accepts the following parameters:
|
This example demonstrates the following concepts:
private void axApplicationMgr_ReportError(object sender, NationalInstruments.TestStand.Interop.UI.Ax._ApplicationMgrEvents_ReportErrorEvent e) { Console.WriteLine("Error " + e.errorCode + ": " + e.errorMessage); //this isn't working because of appdomain stuff axApplicationMgr.ExitCode = e.errorCode; }
axApplicationMgr.AddCommandLineArgumentsHelp("[/SimulateFailure <failures>]", "<failures>: components to fail separated by spaces.\nvalid parameters are: Keyboard, Video, Power, CPU, ROM, & RAM", "");
private void axApplicationMgr_UserMessageEvent(object sender, NationalInstruments.TestStand.Interop.UI.Ax._ApplicationMgrEvents_UIMessageEventEvent e) { if (e.uiMsg.Event == UIMessageCodes.UIMsg_UserMessageBase + 1) { SequenceContext SeqContext = e.uiMsg.ActiveXData as SequenceContext; if (SeqContext == null) return; //Instead of erroring when SeqContext isn't passed, we will ignore this message as to not break other client files that use the same UI message code. try { SeqContext.Locals.SetValBoolean("UiMsgHandled", 0, true); SeqContext.Locals.SetValNumber("KeyboardValue", 0, Fails.Keyboard); SeqContext.Locals.SetValNumber("VideoValue", 0, Fails.Video); SeqContext.Locals.SetValBoolean("PowerFail", 0, Fails.Power); SeqContext.Locals.SetValBoolean("CPUFail", 0, Fails.CPU); SeqContext.Locals.SetValBoolean("ROMFail", 0, Fails.ROM); SeqContext.Locals.SetValBoolean("RAMFail", 0, Fails.RAM); } catch (Exception theException) { Console.WriteLine("Error :" + theException.Message); Application.Exit(); } } }
Note: By default, TestStand shows dialogs under certain conditions. This can cause hangs when automating sequence execution without user input, such as when ran from a CI Server. In order to prevent popups that require user input, configure the following options:
TestStand 2014 SP1 or later
Visual Studio 2015 or later
LabWindows/CVI Runtime Engine 2015 or later
TestExec /?
TestExec /runEntryPoint "Single Pass" "<ExampleDir>\TestSequence\Computer Motherboard Test Sequence.seq" /SimulateFailure Keyboard Video RAM /quit
TestStand Help: ProcessUserCommandLineArguments Event
TestStand Help: Configuring Sequence Editor and User Interface Startup Options
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
Very useful ! I guess i begin to understand how to really use axApplicationManager to run my sequences programmatically !
As described in Overview, i need to run my sequences from a CI Server, so this example is absolutely matching my needs.
Nevertheless, i am not able to report errors: when parameter is not correct and i set:
e.errorProcessing = ProcessCommandLineErrors.ProcessCommandLineError_CustomError; e.errorMessage = "Invalid Command Line Argument: " + e.arguments[e.currentArgument];
i have no error raised...
I set options as you recommand about StationOptions, log in and /quit parameter...
Any idea ? thanks.
Hey Antoine,
I don't have a chance to dig too much into this right now, but I'll take a look later. Setting that error should trigger the axApplicationMgr_ReportError event that is also customized in this example. I just noticed a comment i left, but don't remember why i never revisited it.
Console.WriteLine("Error " + e.errorCode + ": " + e.errorMessage); //this isn't working because of appdomain stuff
Pretty vague i know... but for starters I would put a breakpoint there and see if your error message is making it to this callback.
-Trent
Hi,
Thanks for reply. Actually that's the blocking point: inserting a breakpoint here, or adding methos to display log messages, or message boxes has no effect here. It means the exception is not raised, and execution never goes through axApplicationManager_reportError method.
private void axApplicationMgr_ReportError(object sender, NationalInstruments.TestStand.Interop.UI.Ax._ApplicationMgrEvents_ReportErrorEvent e) { TSUIlogger.Error("Error " + e.errorCode + ": " + e.errorMessage); MessageBox.Show(this, ErrorMessage.AppendCodeAndDescription(this.axApplicationMgr, e.errorMessage, e.errorCode), "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); Console.WriteLine("Error " + e.errorCode + ": " + e.errorMessage); axApplicationMgr.ExitCode = e.errorCode;
}
I don't understand why, because documentation expressively specify that set value for
e.errorProcessing = ProcessCommandLineErrors.ProcessCommandLineError_CustomError;
should automatically raise event for reportError method, and my axApplicationManager has event property for ReportError attached to corresponding method...
Thanks for your time !
Antoine
Hey Antoine,
I just played around with this some and it looks like the error is actually getting reported prior to this event being called. it does print the error to the console, but it never calls that callback (because the error is already handled by the appMgr):
Hi
Thanks for this helpfully example.
Unfortunately I have still some struggle with the "no login message box" part. I did as described and while I am opening the Teststand Sequence Editor, the login message box doesn't appear, but if I start the example code application, the message box shows up.
Could you help me to find out, what I have forgotten or did wrong?
Thanks for your help,
Dani
I'm trying to run a sequence using command line argument but my sequence is ending up with the below error.
Thank you in advance,
Since this isn't specific to custom commands, you should post your question to the normal TestStand forums:
https://forums.ni.com/t5/NI-TestStand/bd-p/330
Also, you should include the specific command that you're which throws this error.
-Trent