How to pause a TestPlan and resume the TestPlan?

I am trying to write a GUI. I want to pause a TestPlan if the user clicks a Pause button and resume the paused TestPlan if the user click a Resume button. But I cannot find a member function in TestPlan class to do this. Can anyone help me on how to pause a TestPlan and resume the TestPlan? Thanks a lot.

This can be done using the TestPlan.OnBreakOffered event. Just pause the thread from the event handler while you want the test plan to be paused.

Note that you can only stop between steps or when steps explicitly offers it.

It really works. Thanks for your help. My code is like this:

TestPlan myTestPlan = new TestPlan();
Boolean isPauseButtonClicked = false;
private void Run_Click(object sender, RoutedEventArgs e)
DelayStep delayStep = new DelayStep();
delayStep.Name = “delay”;
delayStep.DelaySecs = 3;
DelayStep delayStep2 = new DelayStep();
delayStep2.Name = “delay2”;
delayStep2.DelaySecs = 4;

myTestPlan.BreakOffered += _testplan_TestStepPaused;

ThreadStart start = delegate ()
	myTestPlanRun = myTestPlan.ExecuteAsync(resultListeners, null, null, cancellationToken).Result;
new Thread(start).Start();

private void PauseButton_Click(object sender, RoutedEventArgs e)
isPauseButtonClicked = !isPauseButtonClicked

void _testplan_TestStepPaused(object sender, BreakOfferedEventArgs e)


ok, bonus tip :slight_smile: If you want to execute another step instead of the next in the sequence. You can set e.SuggestedNextStep = otherstep.Id;

This usually works if it is the parent step or a sibling step.

1 Like

Thanks. By the way, which function should I call if I want to Abort the execution of current TestPlan? Is it the TapThread.Abort() to Stop the execution of the TestPlan?

Yes, that is the one, but you need to make sure that it is the actual test plan thread. Otherwise you risk aborting your GUI thread or something like that. I’d recommend you do like this:

    // run the plan inside a new thread context.
    TapThread.WithNewContext(() =>
         // notify the class that
         planThread = TapThread.Current;
         // execute the test plan.
    // ...
    // When you need to abort the test plan you can do