TestCase Object

Applies to TestComplete 14.20, last modified on September 11, 2019

Description

TestComplete treats tests (script routines, keyword tests and so on) you add to the Test Items page of your project and BDD scenarios as separate test cases. You can also mark arbitrary parts of the script code as test cases.

The TestCase object provides information about the currently running test case. To get the object in your test, use the aqTestCase.CurrentTestCase property.

Members

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

Highlight search results