Stopping Tests on Timeout

Applies to TestComplete 14.40, last modified on April 22, 2021

You can set a timeout for automated tests to make sure the tests do not take longer than they should. There are several ways to specify a test timeout:

Use a Timeout for Test Items

Test items define the test run order when you run the entire project or project suite. You can configure test items and their timeouts on the Test Items page of your project or project suite.

When a test item’s timeout elapses, TestComplete logs an error. To stop the entire project on a timeout error, set the On error property of your test items to Stop project. To stop the current test item without stopping the entire project on a timeout error, set the On error property of your test items to Stop current item.

TestComplete ignores the test item timeout in the following cases:

  • The test is run not as a test item. For example, from the Project Explorer.

  • The test item has a timeout of 0.

  • You have a handler for the OnTimeout event that sets the Params.Break property to False.

Use a Timeout Timer

When you run automated tests individually (for example, from the Project Explorer as opposed to running the entire test project), you can use a timer to stop the test on timeout. A timer runs some code at regular time intervals. You can set the timer interval equal to the test timeout and call the Runner.Stop method from the timer’s code to stop the test.

JavaScript, JScript

// Unit1

function Main()
{
  // Create a 30-second timeout timer
  Utils.Timers.Add(30000, "Unit1.TimeoutTimer", true);

  // This loop will be stopped after about the 30th iteration
  for (var i = 1; i <= 100; i++)
  {
    Log.Message(i);
    Delay(1000);
  }
}
 
function TimeoutTimer()
{
  Log.Message("The test timeout has been reached... Stopping the test.");
  Runner.Stop();
}

Python

# Unit1

def Main():
  # Create a 30-second timeout timer
  Utils.Timers.Add(30000, "Unit1.TimeoutTimer", True)

  # This loop will be stopped after about the 30th iteration
  for i in (1, 100):
    Log.Message(i)
    Delay(1000)

def TimeoutTimer():
  Log.Message("The test timeout has been reached... Stopping the test.")
  Runner.Stop()

VBScript

Sub Main
  ' Create a 30-second timeout timer
  Utils.Timers.Add 30000, "Unit1.TimeoutTimer", true

  ' This loop will be stopped after about the 30th iteration
  Dim i
  For i = 1 To 100
    Log.Message i
    Delay 1000
  Next
End Sub
 
Sub TimeoutTimer
  Log.Message "The test timeout has been reached... Stopping the test."
  Runner.Stop
End Sub

DelphiScript

procedure Main;
var i;
begin
  // Create a 30-second timeout timer
  Utils.Timers.Add(30000, 'Unit1.TimeoutTimer', true);

  // This loop will be stopped after about the 30th iteration
  for i := 1 to 100 do
  begin
    Log.Message(i);
    Delay(1000);
  end;
end;
 
procedure TimeoutTimer;
begin
  Log.Message('The test timeout has been reached... Stopping the test.');
  Runner.Stop;
end;

C++Script, C#Script

// Unit1

function Main()
{
  // Create a 30-second timeout timer
  Utils["Timers"]["Add"](30000, "Unit1.TimeoutTimer", true);

  // This loop will be stopped after about the 30th iteration
  for (var i = 1; i <= 100; i++)
  {
    Log["Message"](i);
    Delay(1000);
  }
}
 
function TimeoutTimer()
{
  Log["Message"]("The test timeout has been reached... Stopping the test.");
  Runner["Stop"]();
}

Specify a Timeout in the Command Line

If you run automated tests from the command line, you can use the /Timeout argument to specify a timeout (in seconds) for your test. This timeout should account for both the test run time and the TestComplete startup time.

TestComplete.exe "C:\Tests\Test.pjs" /r /e /Timeout:600

Possible timeout values are 30 .. 4 294 967 seconds (49.7 days).

See Also

OnTimeout Event
Test Items Page (Project Editor)
Test Items Page (Project Suite Editor)
Timeout Property

Highlight search results