Pass parameters / other values in MacroString

In our setup we need to ask the user to enter the DUT in a certain slot. For this we show a WPF Dialog window with instructions. We would like to pass the slot number to this configurable Dialog window.

To keep things as flexible as possible, it would be nice to be able to use the output of another test step (or any other variable for that matter) in the description text, something like this:

Please enter device in slot {Variables.SlotNumber}

I was hoping this is already supported in OpenTap, for example through the MacroString. However, documentation is scarce. I see you can pass a TestRun object to the MacroString.Exand() function, however, I haven’t been able to find out how to reference other TestSteps and its values from there.

So in conclusion: How do I get other TestStep values into a macrostring, if at all possible. And if not, what would be a good solution for my problem?

Are you using UserInput.Request to show this dialog? I will recommending no coding custom UIs to pop up since it will not work in a cross platform setting.

There is not really any generic way of combining strings in this way at the moment.

No, we use a custom WPF UI implementation based on this BarcodeScanner example. which allows us as well to show images, dropdowns, radiobuttons, etc, something that we found lacking in the current GUI (is there any documentation on the UserInput capabilities?)

So, MacroString does not support anything like this? You cannot access property-values through the TestRun object?

UserInput capabilities are the same as any other settings panel you see. I think the example is from before we had ‘picture’ support. You can check out the SDK examples for more information.

As I remember it MacroString only looks at properties with MetaDataAttribute and it is not really intended for data inside the test plan (as opposed to data ‘about’ the test plan).

Can I change Metadata programatically during runtime, and then get this latest value runtime in the MacroString? That would cover my use case.

You’d have to modify the TestPlanRun instance or create a new one, but yes, that is also possible.

You can also use the overload that takes a Dictionary of additional replacements.

var test = new Dictionary<string, object>();
test["test-macro"] = 1.0;

var result = new MacroString(){Text = "<test-macro>"}.Expand(null, null, null, test);
// result should be "1.0".
1 Like