CurrentTestCase Property

Applies to TestComplete 15.45, last modified on December 01, 2022

Description

The aqTestCase.CurrentTestCase property returns information on the test case that is currently running. It can be:

  • The tests specified in the Execution Plan editor of your project. By default, TestComplete treats all the tests added to the editor as test cases.

  • Code fragments marked as test cases by using the aqTestCase.Begin and aqTestCase.End methods.

  • Tests that are run by specifying their tags.

  • BDD scenarios.

Use the Name property of the resulting object to get the name of the running test.

Requirements

TestComplete version 14.2 or later.

Declaration

aqTestCaseObj.CurrentTestCase

Read-Only Property A TestCase object
aqTestCaseObj An expression, variable or parameter that specifies a reference to an aqTestCase object

Applies To

The property is applied to the following object:

Property Value

A TestCase object that provides information on the current test case.

If no test case is running, the property returns an empty value (null in JavaScript, JScript, C#Script and C++Script, None in Python, Nothing in VBScript, nil in DelphiScript).

Example

The following sample shows how to post the name of the current test case to the test log:

JavaScript, JScript

function Main()
{
  var page = Aliases.browser.page;
  var panel = page.Aspnetform.panel;

  …
  // Sets the beginning of the "Create an order" test
  aqTestCase.Begin("Create an order");
  try{

    page.Aspnetform.table.cell1.linkOrder.Click();
    …

  }
  catch (e){
    Log.Warning("Test case \"" + aqTestCase.CurrentTestCase.Name + "\" failed");
  }

  finally{
    // Sets the end of the "Create order" test
    aqTestCase.End();
  }

  …

  Aliases.browser.Close();
}

Python

def main():
  page = Aliases.browser.page 
  panel = page.Aspnetform.panel
  
  # Sets the beginning of the "Create an order" test
  aqTestCase.Begin("Create an order");
  try:
    page.Aspnetform.table.cell1.linkOrder.Click()
    #...
  except Exception as e:
    Log.Warning("Test case \"" + aqTestCase.CurrentTestCase.Name + "\" failed")
  finally:
    # Sets the end of the "Create order" test
    aqTestCase.End()
  
  #...
  Aliases.browser.Close()

VBScript

Sub Main
  Dim page
  Set page = Aliases.browser.page
  Dim panel
  Set panel = page.Aspnetform.panel
  …
  ' Sets the beginning of the "Create an order" test
  aqTestCase.Begin("Create an order")
  On Error Resume Next

    Call page.Aspnetform.table.cell1.linkOrder.Click
    …

  If Err.Number <> 0 Then
    Log.Error("Test case """ & aqTestCase.CurrentTestCase.Name & """ failed")
  End If
  ' Sets the end of the "Create order" test
  aqTestCase.End

  …

  Call Aliases.browser.Close
End Sub

DelphiScript

procedure Main;
var page, panel;
begin
  page := Aliases.browser.page;

  panel := page.Aspnetform.panel;
  …
  // Sets the beginning of the "Create an order" test
  aqTestCase.Begin('Create an order');
  try
  begin
    page.Aspnetform.table.cell1.linkOrder.Click;
    …
  end;
  except
    Log.Warning('Test case "' + aqTestCase.CurrentTestCase.Name + '" failed');
  end;
    // Sets the end of the "Create order" test
    aqTestCase.End;
  …

  Aliases.browser.Close();
end;

C++Script, C#Script

function Main()
{
  var page = Aliases["browser"]["page"];
  var panel = page["Aspnetform"]["panel"];

  …
  // Sets the beginning of the "Create an order" test
  aqTestCase["Begin"]("Create an order");
  try{

    page["Aspnetform"]["table"]["cell1"]["linkOrder"]["Click"]();
    …

  }
  catch (e){
    Log["Warning"]("Test case \"" + aqTestCase["CurrentTestCase"]["Name"] + "\" failed");
  }

  finally{
    // Sets the end of the "Create order" test
    aqTestCase["End"]();
  }

  …

  Aliases["browser"]["Close"]();
}

See Also

aqTestCase Object
About Test Cases and Summary Reports
Getting Current Test Name
Name Property

Highlight search results