Caption Property

Applies to TestComplete 14.10, last modified on June 5, 2019

Description

The TestItemElement.Caption property lets you get the caption of the test that is executed by the test item. This is the same value that you see in the Execution Entity column next to the test item’s name on the Test Items page in the Project Editor.

The returned value consists of the test category (that is the name of the project item or its child element that holds the given test) and the test name, for example, KeywordTests - KeywordTest1 or Script\Unit1 - Main.

Declaration

TestItemElementObj.Caption

Read-Only Property String
TestItemElementObj An expression, variable or parameter that specifies a reference to a TestItemElement object

Applies To

The property is applied to the following object:

Property Value

A string holding the test caption.

Example

The following example obtains the name of the currently executed test and posts this name to the test log:

JavaScript, JScript

function Test()
{
  var Tests, TestItem, Test;
  // Obtains the project’s test items
  Tests = Project.TestItems;
  // Obtains the test item which is currently running
  TestItem = Tests.Current;
  // Obtains the test executed by the test item
  Test = TestItem.ElementToBeRun;
  // Posts the name of the executed test to the log
  Log.Message("The " + Test.Caption + " test is being executed.");
}

Python

def Test():
  # Obtains the project's test items
  Tests = Project.TestItems
  # Obtains the test item which is currently running
  TestItem = Tests.Current
  # Obtains the test executed by the test item
  Test = TestItem.ElementToBeRun
  # Posts the name of the executed test to the log
  Log.Message("The " + Test.Caption + " test is being executed.")

VBScript

Sub Test
  Dim Tests, TestItem, Test
  ' Obtains the project’s test items
  Set Tests = Project.TestItems
  ' Obtains the test item which is currently running
  Set TestItem = Tests.Current
  ' Obtains the test executed by the test item
  Set Test = TestItem.ElementToBeRun
  ' Posts the name of the executed test to the log
  Log.Message("The " & Test.Caption & " test is being executed.")
End Sub

DelphiScript

procedure Test();
var Tests, TestItem, Test;
begin
  // Obtains the project’s test items
  Tests := Project.TestItems;
  // Obtains the test item which is currently running
  TestItem := Tests.Current;
  // Obtains the test executed by the test item
  Test := TestItem.ElementToBeRun;
  // Posts the name of the executed test to the log
  Log.Message('The ' + Test.Caption + ' test is being executed.');
end;

C++Script, C#Script

function Test()
{
  var Tests, TestItem, Test;
  // Obtains the project’s test items
  Tests = Project["TestItems"];
  // Obtains the test item which is currently running
  TestItem = Tests["Current"];
  // Obtains the test executed by the test item
  Test = TestItem["ElementToBeRun"];
  // Posts the name of the executed test to the log
  Log["Message"]("The " + Test["Caption"] + " test is being executed.");
}

See Also

Test Items Page (Project Editor)
ElementToBeRun Property

Highlight search results