# Always run steps(s)

**URL:** <https://forum.opentap.io/t/always-run-steps-s/1021>\
**Category:** Technical\
**Created:** [February 6, 2023, 12:26pm UTC](https://forum.opentap.io/t/always-run-steps-s/1021 "2023-02-06T12:26:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![benstreek](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@benstreek](https://forum.opentap.io/u/benstreek)\
**Post date:** [February 6, 2023, 12:26pm UTC](https://forum.opentap.io/t/always-run-steps-s/1021/1 "2023-02-06T12:26:13Z")

</div>

Say I have a safety tester situation, where I need to prevent physical access to the DUT while the test is running, and a test plan something like this.  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/opentap/original/1X/f5f5f4bcbb0ca907d7b75c86a8c3cf052d4f70e7.png)

If I have Break on Fail in Engine Settings, and ‘Some Test’ fails, how can I ensure ‘Remove Power’, ‘Delay’ and ‘Unlock Interlock’ still run?

I thought I might be able to have the Enigine Settings only on ‘Break on Error’ then define ‘Some Test’ etc in a Sequence with Break on Fail and still have the controlled shutdown steps run but no luck, unfortunately.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/opentap/original/1X/809d549efd371fefac34950cf61b028519cece66.png)

I could always just execute a plan after this that waits a bit and then unlocks the interlock, is that going to be the more sensible approach?

---

<div class="post-metadata">

**Author:** ![GoranJohnsson](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/goranjohnsson/32/140_2.png) [@GoranJohnsson](https://forum.opentap.io/u/GoranJohnsson)\
**Post date:** [February 6, 2023, 3:55pm UTC](https://forum.opentap.io/t/always-run-steps-s/1021/2 "2023-02-06T15:55:04Z")

</div>

One way would be to implement the PostPlanRun() method in the ‘must-always-run steps’ and do the  
clean-up there. If implemented, PostPlanRun() will be executed after the last teststep even if testplan fail or error.

---

<div class="post-metadata">

**Author:** ![btyilmaz](https://avatars.discourse-cdn.com/v4/letter/b/a3d4f5/32.png) [@btyilmaz](https://forum.opentap.io/u/btyilmaz)\
**Post date:** [February 7, 2023, 7:53am UTC](https://forum.opentap.io/t/always-run-steps-s/1021/3 "2023-02-07T07:53:15Z")

</div>

Similiar to @GoranJohnsson 's answer, you can implement the required operations in the Close() method of the DUT resource.

---

<div class="post-metadata">

**Author:** ![benstreek](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@benstreek](https://forum.opentap.io/u/benstreek)\
**Post date:** [February 8, 2023, 8:43am UTC](https://forum.opentap.io/t/always-run-steps-s/1021/4 "2023-02-08T08:43:56Z")

</div>

Thanks for the suggestions, pretty much what I was thinking.  
It doesn’t quite feel right to implement this in the PostPlanRun for the ‘Apply Power’ (yet) as it’s just a generic SetDigitalOutput step. Maybe if I made a dedicated ApplyPower step with Connection and Delay properties it might be a better fit.

I think it’d be nice to be able to build this kind of functionality out of lower-level test steps, though. Just from the perspective of someone examining/modifying the plan in Editor.

I think I’ll just add a delay after executing the plan in my GUI for now while I mull it over.

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [February 8, 2023, 9:10am UTC](https://forum.opentap.io/t/always-run-steps-s/1021/5 "2023-02-08T09:10:30Z")

</div>

I think what was already stated are good suggestions, but you can also try this:

Since you have already programmed a Lock/unlock procedure, I suggest you turn that into one step that locks during child step execution. For example like this:

```cs
public override void Run(){

    LockInterlock();    
   try{
        RunChildSteps();
   }catch{
        UnlockInterlock();
   }
}

```

Then you just need to nest all the other test logic inside that.

---

<div class="post-metadata">

**Author:** ![benstreek](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@benstreek](https://forum.opentap.io/u/benstreek)\
**Post date:** [February 17, 2023, 12:38pm UTC](https://forum.opentap.io/t/always-run-steps-s/1021/6 "2023-02-17T12:38:00Z")

</div>

Thanks, Rolf.  
I settled on a ‘With Connection’ step, very similar your sample, that makes the connection before running child steps then breaks the connection with an optional delay in the finally block. I use the connection that applies power, since it’s really a delay after removing power that I want. Then I hand off to the app that runs the plan to deal with unlocking the interlock.
