What is the Best Way to Grab the Iteration Value in a Sweep/Repeat Step?

I’m trying to pass the Iteration Value of either of these flow control steps to a Result Listener. What is the best way to have a result listener access this data? I’m trying to have my Result Listener print this value OnTestStepRunStart/Complete.

1 Like

Hello Ivan,

I would access the iteration resource from the parent and then publish the string so the result listener can grab it. First I added a reference to the package OpenTap.Plugins.BasicSteps:

image

Then I added a test step which access the parent resource:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using OpenTap;

namespace OpenTap.Plugins.Test1
{
[AllowAsChildIn(typeof(OpenTap.Plugins.BasicSteps.RepeatStep))]
[Display(“PrintIteration”, Group: “OpenTap.Plugins.Test1”, Description: “Insert a description here”)]
public class PrintIteration : TestStep
{
public string TableName { get; set; }
public string ColumnName { get; set; }

    public PrintIteration()
    {
        TableName = "SomeTableName";
        ColumnName = "SomeColumnName";
    }

    public override void Run()
    {
        // Get Iteration info from parent step
        String strIterationInfo = GetParent<OpenTap.Plugins.BasicSteps.RepeatStep>().IterationInfo;
        Log.Debug("Iteration Info: " + strIterationInfo);

        // Publish so result listener can get this
        Results.Publish(TableName, new { ColumnName = strIterationInfo });
    }
}

}

The test step is allowed as child in a Repeat step, every time the test is executed the Parent.IterationInfo is obtained and published, the highlighted rows show the iteration info string:

Then you can access it from your custom result listener.

Let me know if this helps,

Carlos Montes

2 Likes

Thank You Carlos, this helped me a lot!

1 Like

Another thumbs up as the iteration output is calculated differently in repeat and sweep steps. When simply accessing the iteration string of a sweep I was getting system errors but it worked fine when accessing the same output in a repeat step. I assume the failure has something to do with the Lambda function, but accessing via Parent gets around the issue.

1 Like