Stop an API test run

Relevant for: API testing only

Using custom code, you can stop a test run. This is useful if a condition in your test fails, and you do not want to continue the test run.

To stop the test run:

  1. In the canvas, select the step on which you want to stop the test run (if necessary).

  2. In the Properties pane, open the Events tab .

  3. In the Events tab, create an event handler. The TestUserCode.cs file opens. The event you select depends on the test property you want to ensure is correct and where that property occurs in the test flow.

    Tip: To differentiate this event from other default events, enter a descriptive name like stopTestScript in the event name field.

  4. In the TODO section of the TestUserCode.cs file, enter an if statement for the current activity.

    For details on if statements in C#, see

  5. Below the if statement in the TestUserCode.cs file, enter the value you want to report using the following syntax:


If the condition entered in your event is not met, UFT One immediately stops the test run, and does not display test results. If the condition is met, the test run continues.

For example, the following code stops a test run on a SOAP Response step.

This code is set on the OnReceiveResponse event, given the name stopTestScript. It stops the test run if the SOAP response returns a fault:

String node_xpath = "/*local-name(.)='Envelope'][1]/*local-name(.)='Body'][1]";