How to get parameters passed to a testplan

I have been asked to add the ability to print steps that fail to a receipt printer.

I made a result logger plugin that does this by saving to a file which is good enough, but I need to print identifying information to the beginning of the test fail output.

In my operator interface I have the information entered and it then passes this to the testplan as external parameters. So now I want to write all the testplan external parameters to the printer file. When I added iterating through the TestPlanRun parameters I get things like the operator, station ID and plug in versions, but I can’t figure out how to get the parameters I passed.

I see TestPlan has an ExternalParameters property, but the TestPlanRun does not. I even tried asking CoPilot to help, but its changes to the code don’t list anything, so are useless. I thought about putting code to write out the parameters after they get passed to a test step, but that seems to be cumbersome and would put the information mixed in with any step that failed before it.

Can someone point me to a way to write the External Parameters passed to a testrun so I can write them out?

Rob

Hi @robert.lamoreaux,

I think the right behavior would be for the TestPlanRun to have the parameters reflected in the TestPlanRun.Parameters property. It seems that today they are not.

Since you have your own operator interface, you might be able to add the parameters as meta data parameters of the test plan run. This can be done like this:


            var param = tp.ExternalParameters.Add(myStep, mySetting, "Param1");
            param.Value = 1234;

            var planrun = tp.Execute(ResultSettings.Current, metaDataParameters:[new ResultParameter("", "Param1", 1234)]);

Rolf,

I’ll look at that as I get time. I was asked to prioritize other tasks (our group got sold to another company) so it might be a bit.
I am not sure what to use for the myStep and mySetting. would that be the step that receives the parameter for logging (by name or what), and the field name in the step?
Right now this is the code I have for pushing the parameters:
void PushExternalParameters(TestPlan plan, params (string Name, object Value)[] values)
{
foreach (var (name, val) in values)
{
//Added
//var param1 = plan.ExternalParameters.Add(step, setting, name);
ExternalParameter param = plan.ExternalParameters.Get(name);
if (param == null)
{
string guiName = $“Parameters \\ {name}”;
param = plan.ExternalParameters.Get(guiName);
}

        if (param != null)
        {
            try { param.Value = val; }
            catch (Exception ex) { Log.Warning("Could not set External Parameter '{0}' to '{1}': {2}", name, val, ex.Message); }
        }
        else Log.Warning("External Parameter '{0}' was not found on this plan. Is the property parameterized?", name);
    }
}

Ok, actually that makes it a bit simpler.

You track can store the external parameters as ResultParameters like this:

void PushExternalParameters(TestPlan plan, List<ResultParameter> externalParams (string Name, object Value)[] values)
{
foreach (var (name, val) in values)
{
ExternalParameter param = plan.ExternalParameters.Get(name);
if (param == null)
{
string guiName = $“Parameters \\ {name}”;
param = plan.ExternalParameters.Get(guiName);
}

        if (param != null)
        {
            try { param.Value = val; 
                      externalParams.Add(new ResultParameter("",  param.Name, param.Value)
}
            catch (Exception ex) { Log.Warning("Could not set External Parameter '{0}' to '{1}': {2}", name, val, ex.Message); }
        }
        else Log.Warning("External Parameter '{0}' was not found on this plan. Is the property parameterized?", name);
    }
}

Then combine it with TestPlan.Execute like this:

List<ResultParameter> parameters = new List<ResultParameter>();
PushExternalParameters(tp, parameters, values);

var planrun = tp.Execute(ResultSettings.Current, metaDataParameters: parameters);