From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Set variable when step fails

Solved!
Go to solution

Hello!

 

Is it possible to set a variable (or two) in a step, if the step fails? 

 

I've looked at this thread: http://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

 

 

0 Kudos
Message 1 of 11
(5,147 Views)

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

0 Kudos
Message 2 of 11
(5,132 Views)

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..

0 Kudos
Message 3 of 11
(5,124 Views)

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

0 Kudos
Message 4 of 11
(5,120 Views)

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.

0 Kudos
Message 5 of 11
(5,119 Views)
Solution
Accepted by topic author raknessindre

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

Message 6 of 11
(5,106 Views)

This was exactly what I was looking for! Thank you for your help!

 

Regards,

Sindre

0 Kudos
Message 7 of 11
(5,094 Views)

You're welcome, glad I could help Smiley Happy

Charlie Rodway | Principal Software Engineer | Certified TestStand Architect (CTA)

Computer Controlled Solutions Ltd | NI Silver Alliance Partner | GDevCon#1 Sponsor

0 Kudos
Message 8 of 11
(5,086 Views)

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?

 

 

0 Kudos
Message 9 of 11
(4,826 Views)

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

0 Kudos
Message 10 of 11
(4,823 Views)