# Access test step result before it is published

**URL:** <https://forum.opentap.io/t/access-test-step-result-before-it-is-published/686>\
**Category:** Technical\
**Created:** [May 9, 2022, 7:22am UTC](https://forum.opentap.io/t/access-test-step-result-before-it-is-published/686 "2022-05-09T07:22:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chandrima.dasgupta](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@chandrima.dasgupta](https://forum.opentap.io/u/chandrima.dasgupta)\
**Post date:** [May 9, 2022, 7:22am UTC](https://forum.opentap.io/t/access-test-step-result-before-it-is-published/686/1 "2022-05-09T07:22:59Z")

</div>

Hi there,  
I am currently trying to achieve retry of test step for few times if it fails. Also, I want to only publish the last retry result of the test step. I have tried using Retry test step but it seems to publish all the retry results. Has anyone already done that before or know how to do it?  
Thanks,  
Chandrima

---

<div class="post-metadata">

**Author:** ![diego\_tacconi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/diego_tacconi/32/141_2.png) [@diego\_tacconi](https://forum.opentap.io/u/diego_tacconi)\
**Post date:** [May 9, 2022, 2:21pm UTC](https://forum.opentap.io/t/access-test-step-result-before-it-is-published/686/2 "2022-05-09T14:21:40Z")

</div>

Hi Chandrima,

I have been using the test step below to run all child steps until all verdicts are passing or the max iteration is reached.

I hope this helps,  
Diego

```csharp
using System.ComponentModel;
using System.Xml.Serialization;
using OpenTap;

namespace TapExtensions.Steps.FlowControl
{
    [Display("Retry",
        Groups: new[] { "TapExtensions", "Steps", "FlowControl" },
        Description: "Run all child steps until all verdicts are passing or max iteration is reached.")]
    [AllowAnyChild]
    public class Retry : TestStep
    {
        #region Settings

        [Display("Max repeat count", "Maximum number of iteration attempts for repeating child steps")]
        public uint MaxIteration { get; set; } = 3;

        [XmlIgnore]
        [Browsable(false)]
        public int Iteration { get; set; }

        #endregion

        public override void Run()
        {
            Iteration = 0;
            while (Iteration < MaxIteration)
            {
                Iteration++;

                if (Iteration > 1)
                    Log.Warning($"Retrying attempt {Iteration} of {MaxIteration} ...");

                ResetResultOfChildSteps();
                RunChildSteps();
                Verdict = Verdict.NotSet;
                UpgradeVerdictWithChildVerdicts();

                // Exit loop if retry attempt is successful
                if (Verdict == Verdict.Pass)
                    break;
            }
        }

        private void ResetResultOfChildSteps()
        {
            var enabledChildSteps = RecursivelyGetChildSteps(TestStepSearch.EnabledOnly);
            foreach (var step in enabledChildSteps)
                step.Verdict = Verdict.NotSet;
        }

        private void UpgradeVerdictWithChildVerdicts()
        {
            var enabledChildSteps = RecursivelyGetChildSteps(TestStepSearch.EnabledOnly);
            foreach (var step in enabledChildSteps)
                UpgradeVerdict(step.Verdict);
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![chandrima.dasgupta](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@chandrima.dasgupta](https://forum.opentap.io/u/chandrima.dasgupta)\
**Post date:** [May 10, 2022, 3:04am UTC](https://forum.opentap.io/t/access-test-step-result-before-it-is-published/686/3 "2022-05-10T03:04:20Z")

</div>

Hi diego,

Thanks for your response. Currently OpenTAP already provides one Repeat test step for the same. But even there it still publishes all the results(3 results if there were 3 retries done). What I am looking for is to only publish the final result of the retries. Did you by any chance done that before?

Thanks,  
Chandrima

---

<div class="post-metadata">

**Author:** ![carlos.montes](https://avatars.discourse-cdn.com/v4/letter/c/f1d935/32.png) [@carlos.montes](https://forum.opentap.io/u/carlos.montes)\
**Post date:** [May 10, 2022, 5:47am UTC](https://forum.opentap.io/t/access-test-step-result-before-it-is-published/686/4 "2022-05-10T05:47:27Z")

</div>

Hello @chandrima.dasgupta and Welcome to the Opentap forum!

Based on your description I think you will need to implement a custom Result Listener, the Result Listener will receive the Publish for all 3 retries during the OnResultPublished:

```
    public override void OnResultPublished(Guid stepRun, ResultTable result)

```

In here you can validate if you have received a result for a given Guid and only add the values if the result has a verdict of Pass.

Another idea is to filter and only log results with Verdict equal to pass during the OnTestStepRunCompleted:

```
    public override void OnTestStepRunCompleted(TestStepRun stepRun)

```

but the point is that you need a custom result listener to achieve what you are looking for.

Carlos Montes

---

<div class="post-metadata">

**Author:** ![connospp](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@connospp](https://forum.opentap.io/u/connospp)\
**Post date:** [January 26, 2023, 1:11pm UTC](https://forum.opentap.io/t/access-test-step-result-before-it-is-published/686/5 "2023-01-26T13:11:00Z")

</div>

> [@diego\_tacconi](#):
>
> `UpgradeVerdictWithChildVerdicts();`

Thank you @diego_tacconi

Saved my day
