09-30-2016
03:36 AM
- last edited on
12-03-2024
11:49 AM
by
Content Cleaner
Hello!
Is it possible to set a variable (or two) in a step, if the step fails?
I've looked at this thread: https://forums.ni.com/t5/NI-TestStand/Set-a-variable-in-a-post-expression/td-p/1186981 ,
which is somewhat similar to what I'm trying to do.
I want to avoid creating a new step to accomplish this. I know that I cannot use the Post Expression to check if the step failed, since the Status Expression is evaluated after the Post Expression. The solution to the thread linked to above was to use the Custom Condition Expression instead of the Post Expression, and I've got the following to work there:
(Step.Result.Status == "Passed") ? (Locals.Passed = False) : (Locals.Passed = True)
But, the problem I have here is that I want to write to a String and Number (Error text and error code) variable instead of a Boolean (Locals.Passed). How can I write to something else than a Boolean? Is it possible? Or do I have to create a new step for each test step?
This does not work:
(Step.Result.Status == "Passed") ? (Locals.Error = "No error") : (Locals.Error = "Error")
Regards,
Sindre
Solved! Go to Solution.
09-30-2016 04:13 AM - edited 09-30-2016 04:13 AM
Hi Sindre,
The Custom Condition expression always needs to evaluate to a boolean, so your expression can be modified to do this:
((Step.Result.Status == "Passed") ? (Locals.Error = "No error") : (Locals.Error = "Error")) == "No error"
I'd rather use a SequenceFilePostStepFailure to set the Error information than do it this way, but if this works for you then I'm glad it helped!
Regards,
Charlie Rodway | Principal Software Engineer | Certified TestStand Architect (CTA)
Computer Controlled Solutions Ltd | NI Silver Alliance Partner | GDevCon#1 Sponsor
09-30-2016 04:42 AM - edited 09-30-2016 04:52 AM
Hi Charlie!
This seems to work, at least for the error text. I still need to write a Number variable as well, for the error code.
Could you provide a brief example of how to use the SequenceFilePostStepFailure or guide me in the right direction? I'd rather do it the right way!
I do not want the user to write the error code or the error text. Thereby, the SequenceFilePostStepFailure has to be able to distinguish between different steps etc. Maybe I can work with two local variables that are set in the precondition of each test..
09-30-2016 04:53 AM
A few questions -
1). Do you want this to apply only to this step? Or a set of steps with the same name/type?
2). Do you want to set locals or would it be better to set Step.Result.Error.Msg & Step.Result.Error.Code?
Charlie Rodway | Principal Software Engineer | Certified TestStand Architect (CTA)
Computer Controlled Solutions Ltd | NI Silver Alliance Partner | GDevCon#1 Sponsor
09-30-2016 04:54 AM
1) This will be applied to multiple steps.
2) I'd prefer to set the variables to locals, since I'm logging them to a database in the end.
09-30-2016 06:56 AM
Hi,
I've put together an example sequence file that uses SequenceFilePostStepFailure to set local variables with an error message and code dependent on which steps failed.
I've also included the steps to set the Step.Result.Error (currently skipped out) as I think this is a nice alternative.
Regards,
Charlie Rodway | Principal Software Engineer | Certified TestStand Architect (CTA)
Computer Controlled Solutions Ltd | NI Silver Alliance Partner | GDevCon#1 Sponsor
09-30-2016 08:01 AM
This was exactly what I was looking for! Thank you for your help!
Regards,
Sindre
09-30-2016 08:04 AM
You're welcome, glad I could help
Charlie Rodway | Principal Software Engineer | Certified TestStand Architect (CTA)
Computer Controlled Solutions Ltd | NI Silver Alliance Partner | GDevCon#1 Sponsor
11-15-2016 11:51 AM
Hi Charlie
Your sequence file sounds like it may help me, however I can't open it. I'm running TS 2013 on Windows 7.
Is there a version incompatability? Could you save as TS 2013?
11-15-2016 11:54 AM
Hi,
Here's the TS 2013 version.
Regards,
Charlie Rodway | Principal Software Engineer | Certified TestStand Architect (CTA)
Computer Controlled Solutions Ltd | NI Silver Alliance Partner | GDevCon#1 Sponsor