How to use scripts/expressions in OpenTap?


What is our problem : if we look at the basic If Step, it has 1 input which is equal to the output Verdict of another Step.

What if we now want to replace that input with an expression, like:
Verdict1 == Verdict.Pass && SumOutput1 = 5.0 ?
We could first implement this in a new custom Step and provide an output that is also a Verdict.
This can then be used in a following If Step.

But for yet another If Step, we want to use a completely different expression, with different/multiple items.
Do we have to write a custom Step again for this? This is getting a little difficult…

The question also arises when, for example, we want to set the ‘Voltage’ input value of a Power Supply Step on the basis of a complex calculation via a script.

We know that there are other sequencers that have something like an Expression builder.
Does such a thing exist for OpenTap or what is the best approach ?



We have this as a feature request. Usually, we have found users build this into their own step but I definitely see the value in having a generic version:

@alexander.larsen , @rolf_madsen thoughts on this?

Hmmm, this wasn’t really my question.

The input of an If Step, as well as all others, should be able to be defined as an expression.
I suspect that OpenTap’s architecture won’t allow this.
But a generic input could be an alternative.

Just curious, what sort of format for the expression would you expect? Like C# code?

The C# syntax style would be perfect, for me.

1 Like

I think this would be great to have. It can probably be added as a plugin.

How do you think this should work though?

  • Is it a separate step type with dynamically added input and output properties plus an expression to specify what should be done with the values?
  • Do we add a capability to right-click any property and add an ‘assign outputs with expression’? This way, TestStep.Enabled could be set based on some external values.

We also think that a plugin would be a great added value, and a perfect fit with the OpenTap concept.
In fact, we absolutely need this to continue using OpenTap.

The question is whether we can get that input dynamic enough.
Are we going to be able to integrate all available Outputs into that expression?
Will we also be able to use settings/properties of the current TestPlan object (such as full path name of current TestPlan,…)
This all seems quite challenging to me.

The disadvantage of only an Expression plugin is that extra (expression) Steps are added in the TestPlan.
Even for very simple expressions that we want to use in an If Step, this is a bit tedious.
That’s not a big deal, but still.

@fostyn would you be interested in co-developing a plugin for this functionality? It sounds like you have a real use case and a good set of challenges you have already thought of. I believe between you and someone on the team we can come up with a good solution.

@brennen_direnzo We’re certainly interested, but unfortunately we cannot free up enough time for this.

1 Like

We have made something similar to what Fostyn mentioned.
But we made it possible by adding user variables feature.


@justin_c_i Nice to see this !
Q: what are ‘user variables’ ?
Q: where is the FIELD coming from, it looks like a collection of ‘user variables’ ?
Q: ever thought of using a C# REPL for that?
For a great open source C# REPL project: C# REPL (WAF)

Hi Fostyn,

what are ‘user variables’ ?
User variables is a new feature that we introduced in our PTEM project.
User variables can pass values in between test steps.

where is the FIELD coming from, it looks like a collection of ‘user variables’ ?
Yes, we can create N number of user variables of different datatype (int, string double etc.)
We have created 250+ test steps, also we can link almost any c# dll to our tap plan.
We have 75+ In built instruments support in our PTEM project.
Also We can support any IVIInstrument using our PTEM project.

ever thought of using a C# REPL for that?
We have not this project, we have added our own Expression builder and validator for this.


Usage of Variables:
In the above tap plan, Current from the power supply is assigned to a user variable(VAR.Current)
this user variable can be used for further processing (eg:if Test step)

1 Like

Hi Justin_c_i,

very interesting… User variables are familiar to us, in our own, non-OpenTap project , hence my interest.
Can the User variables also be linked to the Input(s)/Output(s) of a custom Step?
And can they be parameterized?


1 Like

Hi Fostyn,
Yes . user variables can be linked between input and output of a custom test step.
User variables can be accessed all over the tap plan.
Currently no parametrization is available on user variables.

Note: There is no link between Input/Output attribute of OpenTap
User variables is a sperate feature .

1 Like