07-19-2010 02:25 PM
I have a loop of tests and if one or more tests fails I want to set a variable "failure" that I can use at the end of the loop for a summary data sheet.
In pseudo-code I want:
If step.result.status == "Failed"
then failure = 1
There is no else action so the ?: operator doesn't seem appropriate but I see no IF option. So do I need to write something like:
(step.result.status == "Failed") ? (locals.failure = 1) : (locals.failure = locals.failure)
?
thanx,
jvh
Solved! Go to Solution.
07-19-2010 02:33 PM
Try the following:
Locals.Failure = Step.Result.Status == "Failed" ? 1 : 0
I would be careful on using Step.Result.Status as your comparsion as that is not evaluated until the step is completed.. Hence a post expression would not have that evaluated as Failed yet.. Until the Status expression is evaluated.
Thanks,
PH
07-19-2010 02:42 PM
Thanks, didn't know I could use it that way. I was taught (and NI help desk re-iterated that there had to be expressions that include equal signs on both sides of the ":". I don't want to set it to zero if it passes as that would undo other failures, maybe I could do it more C style:
Locals.Failure += Step.Result.Status == "Failed" ? 1 : 0.
So if "Step.Result.Status" is unsafe what could I use?
thanx,
jvh
07-19-2010 02:46 PM - edited 07-19-2010 02:48 PM
The choices in a conditional operator don't have to be assignments. It may seem a little odd, but you are free to use any expression, such as a constant. Thus:
(step.result.status == "Failed") ? (locals.failure = 1) : (locals.failure = locals.failure)
could be also:
(step.result.status == "Failed") ? (locals.failure = 1) : Nothing
or
(step.result.status == "Failed") ? (locals.failure = 1) : 0
or
(step.result.status == "Failed") ? (locals.failure = 1) : ""
or
(step.result.status == "Failed") ? (locals.failure = 1) : False
07-19-2010 02:56 PM
I thought I had tried a variant of one of your examples with:
(step.result.status == "Failed") ? (locals.failure = 1) : 1. But that is now acceptable, I must have had another mistake.
Again, could you suggest something other than using step.result.status since it may not be reliable?
07-19-2010 03:10 PM
You could drop in a step afterwards and use PreviousStep.Result.Status.
Jim
07-19-2010 03:14 PM - edited 07-19-2010 03:15 PM
If you need an expression evaluated after the status expression, you could put your expression in the Custom Condition of the step's Post Action, with both the true and false outcomes left set to "Goto next step".
07-19-2010 03:25 PM
It seemed to work OK as I had it. But since PH said be wary I thought it might be unreliable.
So's I called Austin and they sez post expressions are after the step is complete and it will be OK. We'll see...
jvh
07-19-2010 03:37 PM
I don't think the person you talked to understood that the expression could depend on the status expression (does your step have a status expression?).
Your best bet is to refer to Table 3-4 Order of Actions a Step Performs in the TestStand reference manual.
07-19-2010 03:42 PM - edited 07-19-2010 03:43 PM
Yes, it does have a status expression:
(Step.Result.Status == "Done" && (Step.TS.SData.ThreadOpt == 0 || Step.TS.SData.ThreadOpt == 3)) ? "Passed" : Step.Result.Status